Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy files using Windows Batch?

I have a directory with several subdirectories with files.
How can I copy all files in the subdirectories to a new location?

Edit: I do not want to copy the directories, just the files...

As this is still on XP, I chose the below solution:

 for /D %S IN ("src\*.*") DO  @COPY "%S\" "dest\"

Thanks!

like image 984
Nescio Avatar asked Oct 09 '08 02:10

Nescio


People also ask

Can you transfer files using cmd?

Use the Copy Command to Transfer Specific Files Right-click the Start button and choose "Command Prompt (Admin)" to open CMD. To copy files, use the copy command from the command line. copy c:\myfile.


2 Answers

The Xcopy command should help here.

XCOPY /E SrcDir\*.* DestDir\

Or if you don't want any of the files in SrcDir, just the sub directories, you can use XCOPY in conjunction with the FOR command:

FOR /D %s IN (SrcDir\*) DO @XCOPY /E %s DestDir\%~ns\
like image 149
Eric Tuttleman Avatar answered Oct 23 '22 09:10

Eric Tuttleman


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

like image 2
Mark Cidade Avatar answered Oct 23 '22 07:10

Mark Cidade