Solved I want xcopy to both copy and rename multiple files

January 24, 2012 at 06:49:33
Specs: Windows XP
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?


See More: I want xcopy to both copy and rename multiple files

Report •

✔ Best Answer
January 30, 2012 at 07:58:13
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.)

How To Ask Questions The Smart Way



#1
January 25, 2012 at 09:11:56
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


Report •

#2
January 26, 2012 at 02:09:52
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.


Report •

#3
January 29, 2012 at 14:32:18
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

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
January 30, 2012 at 03:12:13
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.


Report •

#5
January 30, 2012 at 07:58:13
✔ Best Answer
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.)

How To Ask Questions The Smart Way


Report •

#6
January 30, 2012 at 08:05:38
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 !


Report •

Ask Question