5

I want to copy a file from one folder to another folder which has many sub-folders. Using command line. How can I copy this file to all sub-folders.

Eg. I have a file called Test.txt. I want to copy this file to another folder "Data", which has many subfolders 'Data-1', 'Data-2', 'Data-3' etc. Using command I want to copy this text file to all these sub-folders in a single command.

Dave M
  • 13,200

4 Answers4

0

Assuming by 'MS-DOS' you mean Windows' Command Prompt, use robocopy with the /mir switch:

robocopy /mir <source> <destination>

for all the options this tool can offer type robocopy /?

Azevedo
  • 528
0

Without your paths, command would look like;

for /d %I in ("C:\KData\Data-*") do copy "C:\Tfolder\Test.txt" "%I"

In case your structure changes to just DataSomething and you need more Test files to do the same from same location, command changes slightly, and will work for you in both cases;

for /d %I in ("C:\KData\Data*") do copy "C:\Tfolder\Test*.txt" "%I"

And for funny guy in comments, what version of windows are you using? Repeating "there's no for /D" wont make it more true.Try this, open cmd and paste;

for /? | find "/D"
Danijel
  • 318
0
@echo off
for /d /r "d:\folder 2" %%a in (*) do copy "d:\folder 1\test.txt" "%%a"
foxidrive
  • 291
0

Use the advanced for command...

for /D %%f in ("%1\*") do copy "%2" "%%f\"

  • The first argument is the destination directory
  • The second argument is the file to be copied
Millhorn
  • 113