Xcopy transfer not working - xcopy

I am using the xcopy command to copy files from one directory to another.
I am saving in the text editor as a .bat file and then running as admin.
Here is the command.
xcopy C:\Users\Public\Public Documents\Saved Spectral Files Z:\Contamination_Control\MOC Measurements\MOC Plates Data\Perkin Elmer Data Back-Up\ /d /f /p
The problem is it doesn't work. Not even a notification that anything has happened.
Any help would be appreciated.
Thanks,
N

You have to insert quotation marks around the two file paths, because without them, in my experience with xcopy, doesn't recognize the files. Sidenote: the same applies to the copy function.

As an add-on to the previous answer:
The problem is your empty spaces " " within the paths. For the command to know where one path starts and ends, always use the quotation marks.

Related

Batch script to move zip files based on year modified

I realize there are a lot of questions already answered about doing something similar. I have researched what I am trying to do and didn't find anything that seemed to apply to what I am trying to do. There are a few factors combined in what I am trying to do and I don't know a lot about batch scripting.
First, I need to look at zip files with a certain naming scheme only. The way these are named is file1234.zip, file2345.zip, file3456.zip, etc... This naming scheme is automatically generated and already in place. The number in the name has nothing to do with the date it was modified or created. There are other zip files in the source directory I would want to ignore. This can be solved with wildcards. "file*.zip"
Next, I need to move only certain files fitting the above criteria, that were modified within a specific year. i.e. move zip files modified in 2000 but leave all other files alone. The year the files were modified would be a constant and would be designated in the script.
When combined, if file2345.zip was modified in 2000 and the other files were last modified in other years, then file2345.zip would be moved and all others would be ignored.
What I have learned:
Wildcards are valid characters in the middle of a file name.
To get the dates modified for all files matching my naming criteria
forfiles /M file*.zip /C "cmd /c echo #file #fdate"
With the above, how do I look at just the four-digit year?
I have no objections to using xcopy or robocopy for the actual file move.
Any suggestions or ideas would be greatly appreciated.
Assuming this command dir file*.zip |find /i "file" shows something like this:
18/08/2015 11:58 45,617 file2456.zip
18/08/2015 11:58 156,789 file36789.zip
then this code should work:
#echo off
md "d:\new folder" 2>nul
for /f "tokens=3,*" %%a in ('dir file*.zip ^|find /i "file" ^|find "/2000 "') do move "%%b" "d:\new folder"

Using diff3 where filenames contain a dash (-)

I'm trying to use diff3 in this way
diff3 options... mine older yours
My problem is that I probably can't use it, since all my 3 files contain a "dash" within.
The manual mentions:
At most one of these three file names may be `-', which tells diff3 to read the standard input for that file.
so I probably have to rename filenames before running diff3.
If you know for a better solution or a workaround, please let me know about. Thank you!
At most one of these three file names may be `-', which tells diff3 to read the standard input for that file.
It does not state, that your filenames should not contain dash symbols. It simply says, that if you want to, you can put - instead of one of the names, in which case the standard input will be read instead of reading one of the files.
So, you can have as many dashes in your filenames as you like and diff3 should work just fine.
However, on Windows putting filenames in "" for escaping space characters does not work, and I failed to find a suitable workaround. However, you can automatize the process of renaming files (if the files are relatively small, this would not even be too inefficient):
#echo off
copy %1 tempfile_1.txt
copy %2 tempfile_2.txt
copy %3 tempfile_3.txt
"C:\Program Files (x86)\KDiff3\bin\diff3.exe" -E tempfile_1.txt tempfile_2.txt tempfile_3.txt
del tempfile_1.txt tempfile_2.txt tempfile_3.txt
Put this in a file like diff3.cmd, then run diff3.cmd "first file.txt" "second file.txt" "third file.txt".
P.S. Moving files would be more efficient (if they are on the same disk volume as the script, which they are not in your case), you could even move them back to where they were initially, but for some time they would not be present at their original folder.

edit filename using command prompt

I have a number of files in a folder, by mistaken in some of files I enter the wrong name
for example :
filename like : abcefxyz.txt while I suppose to enter abcdevwxyz.txt
that is I simply want to replace ef string in filename with devw
how can I do this using command prompt?
please help...
EDITED
I have a thousands of files whose name like : SomethingLongString_OutdoorGames_DateTime.txt
(which I suppose to enter) but
Accidently in some of files, may be hundreds or thousands in number, I have enter SomethingLongString_IndoorGame_DateTime.txt
I simply want to replace IndoorGame string in filename with OutdoorGamestring (precisely saying).
Here SomethingLongString and DateTime strings in filename is different for different file.
I think this example is more helpful to understand my problem...
on windows use
I dont know how to replace some chars with others,but u can rename this way
dirpath> ren abcefxyz.txt abcdevwxyz.txt
DUNNO.. if they are all TXT files then isolate them in a folder.
From there use Advanced Renamer to a file with NO extension
this way you can use 26 letters to rename the bunch.
CMD use would be Ren A* A (1,2,3,4 etc)
or XCOPY a* A using an older computer..
in a batch you could use for # (filename) do (ren) statements
Would this help?

Basic script to replace image files in multiple directories

I have a situation where we have several thousand image files that have become corrupted on our server (Windows 2008 R2 x64). I have a working image file that I want to replace the corrupt files with. The files must retain the same name and path (size, timestamps, etc do not matter).
So the basic idea would be to replace each corrupt image file with the working file.
I do not write code, only the occasional windows batch file.
Should I use VB or PowerShell (or something else) for this? What will the script look like for this?
I apologize in advance if this question is too basic for stackoverflow.
You don't really need a batch file,
try looking at the for command
e.g.
FOR /R %f in (*.jpg) DO copy newfile.jpg "%f"
This should do a recursive search and copy newfile.jpg over the jpg's it finds.
It all boils down to how you are identifying the broken jpgs.
When I dont use a wild card for example
FOR /R %f in (broken.jpg) DO copy newfile.jpg "%f"
Then newfile.jpg gets copied to every subdirectory. If I use a wildcard ( *,?) the command works as expected. Is there a way to have this commend work with a (set) that does not contain wildcards?

how to remove a few lines from a Unicode registry file using batch commands in Windows?

I have a program who's generating some data in registry.
I save it with "reg export HKCU\Software\ProgramName\Data data.reg" (Unicode format).
I need to take it to other computer and import it there so the program from that computer could use the data.
But I have to remove some text lines from data.reg. The text lines are easy to find because they contain some strings (for example paths to exe and dlls, specific program settings like "name1=value1", "name2=value2",...).
Now I'm doing this manually (using Wordpad) every few days but maybe there is another way...
Oh and I can't install other programs on these computers (the access is restricted) so I have to use batch/cmd files.
What I tried so far:
- redirecting the export to "con" but is visual only not in a variable;
- using "for /F ..." but this works only with ANSI and removes blank lines.
The lines must be removed before importing because the settings of the program from the first computer must not be loaded into the registry keys of the program from the second computer.
Can somebody please help me...?
Thank you.
Use this code to loop the file contents line by line
FOR /F %z IN (yourfile.reg) DO ...
Then use conditionals to determine if this line is one you want to keep
IF (%z)==[put your key string here]
If so (or if not), then write that variable to the target file
#echo %z >> output.reg
You can replace the filenames with command line arguments, use %1, %2, etc.
All together, then:
FOR /F %z IN (%1) DO IF NOT (%z)==[skip this line] #echo %z >> %2
Since you didn't give some critical details, I am making some assumptions here. Further reading can be found at this excellent resource: http://www.robvanderwoude.com/batchfiles.php
An example would be nice, but could you use reg delete to delete the keys/values you want after importing your .reg file?