tags:

views:

461

answers:

2

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 that?

(ps. i use windows)

+3  A: 

use the 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

Preet Sangha
+1  A: 

You can do this using the for command with the /r switch, which is used to enumerate a directory tree. For example, this will copy the C:\a.jpg file to the C:\Test folder and all of its subfolders:

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

The for /r "C:\Test" %%f in (.) statement enumerates the C:\Test folder and all its subfolders and %%~ff returns the current folder name.

Helen