I can easily use xcopy to copy files to another location xcopy "\\Source\*.*" "\\Destination\" /y/s
but I would then like the copied files to be renamed to append "Copy of " or similar to the start of the file.
I have managed code which will replace the first 8 characters of the filename
xcopy "Source\*.*" "destination\Copy of *.*" /y /s
but haven't a way of appending this.
Can anyone help?
for /r source %a in (*) do copy %a "destination\Copy of %a" /y will work from the command line, add % and \ as neccessary for batch commands
that sould do the trick for you
I have not managed to get this to work. I created a folder called Source with a few files in and another called Destination.
I then added the following code to a batch file -
for /r H:\Source %a in (*) do xcopy %a "H:\Destination\Copy of %a" /y
But when I run the batch file all that happens is that the cmd box flashes open and closed and nothing appears in the destination folder.
The system is XP but I'm not sure why that would make any difference.
The command provided is for direct input. If you're going to put it into a script, you need to change each percent to a double percent. for %%a in (H:\Source\*) do xcopy "%%a" "H:\Destination\Copy of %%a" /y
This looks like it is at least trying to do what I want. Unfortunately, it brings up the File or Directory ? option that seems to affect others. Irrespective of which option I then choose for each file nothing is yet copied.
Easiest solution is just to use copy instead of xcopy:
for %%a in (H:\Source\*) do copy /y "%%a" "H:\Destination\Copy of %%~NXa"(Note: H:\Destination needs to exist before this command runs.)
Okay, that worked a treat .. thank you :) Of course the reason I had chosen to use xcopy as opposed to copy is that I had been using /y/s as the triggers because I wanted sub-directories too.
I know, I'm just being greedy !
| « save input to txt file in... | Monitor Directory for new... » |