Copy to all folders batch file?

走远了吗. 提交于 2019-12-12 18:45:02

问题


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)


回答1:


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




回答2:


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.




回答3:


you can copy a file in all folders of a directory by using following command

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

explanation:

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



来源:https://stackoverflow.com/questions/1321355/copy-to-all-folders-batch-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!