Copy to all folders in batch file?

I want to copy a file (example: a.jpg) to all folders in a directory.

I need something like

copy a.jpg */a.jpg

      

Do you have a batch file that does something like this?

(ps. i am using windows)

+2


source to share


3 answers


use command for command

for /f "tokens=*" %f in ('dir . /ad/b') do copy "a.jpg" "%f" 

      



Remember to use %% f instead of% when placing in a batch file

+5


source


You can do this by using the command for

with a switch /r

that is used to list the directory tree. For example, this will copy the file C: \ a.jpg to the C: \ Test folder and all of its subfolders:

for /r "C:\Test" %%f in (.) do (
  copy "C:\a.jpg" "%%~ff" > nul
)

      



The operator for /r "C:\Test" %%f in (.)

enumerates the C: \ Test folder and all its subfolders and %%~ff

returns the name of the current folder.

+5


source


you can copy the file to all folders of the directory using the following command

for / F% g in ('dir / AD / B / S') DO copy c: \ myfile% g

explanation:

In the above command: -% g is a variable, dir / AD / B / S: - is a command to view all folders and subfolders of a directory, / F: is the switch we used for the command if we want to iterate over the results the command enclosed in a parenthesis (in our case it is ('dir / AD / B / S'), c: \ myfile: is the file that we want to copy in all subfolders

+2


source







All Articles