0

I need a 'Xcopy' or any copy command to copy a file from source to destination and rename the file.

for example

Source directory : C:\Source\

Files in Sourced irectory : textfile.txt ; xmlfile.xml; htmlfile.htm

Destination directory : C:\Destination\

Files in Destination directory: textfile.txt.abc ; xmlfile.xml.abc; htmlfile.htm.abc

lucapette
  • 20,564
  • 6
  • 65
  • 59
BABA
  • 267
  • 4
  • 7
  • 15

2 Answers2

-1

Assuming that you are using Windows Vista/7 or so,

copy C:\Source\*.* C:\Destination\*.*.tmp

The Destination folder has to exist, otherwise the copy will fail. It will not do the copy recursively, but in your example it works perfectly!

Argeman
  • 1,345
  • 8
  • 22
  • thanks for reply.. if i need to copy recursively is there an option? – BABA Apr 17 '12 at 09:43
  • It is getting much more complex then. It is not possible to copy recursively with the copy command only. xcopy can copy recursively but not rename as far as i know – Argeman Apr 17 '12 at 11:01
-1

Use the xcopy command.

Specify your source as a folder (backslash on the end) and the command will operate recursively with the switch /E

xcopy "c:\source\" "c:\destination\" /E

The folder contents will be recursively copied to "c:\destination\"

Finally, use the ren command to rename your folder:

ren "c:\source\destination" "copiedfolder"

Your finished batch file will look like:

xcopy "c:\source\" "c:\destination\" /E
ren "c:\source\destination" "copiedfolder"

As stated in another answer, the destination folder has to exist. If it does not, consider the mkdir command!

As a note, try entering xcopy /? for extended help on the command. /? works with many standard windows commands.

Thiago Sá
  • 832
  • 9
  • 22
Gusdor
  • 14,001
  • 2
  • 52
  • 64