Copying a file to multiple folders in the same directory

北战南征 提交于 2019-11-30 18:20:51

问题


I have a file, lets call it EXAMPLE.DBF

The location of this file is C:\EXAMPLE.DBF

Now I would like to copy this file into multiple folders at another location. These folders are dated Sub-directories so they are named 20140101 - 20141231 and their location would be in d:\bootd\hello\20140101 - 20141231 Not only that but a file named EXAMPLE.DBF already exists in the folders...so it will ask to Copy and Replace. I will need c:\EXAMPLE to copy and replace the existing EXAMPLE.DBF in 365 folders (20140101-20141231) in a different location.

If anyone could help me out with this I will be truly grateful.


回答1:


Directly from the prompt,

for /d %a in (d:\bootd\hello\2014*) do copy /y C:\EXAMPLE.DBF %a\

Will copy C:\EXAMPLE.DBF to each directory of d:\bootd\hello\ which matches the pattern 2014* (ie. simply starts 2014), replacing any existing example.dbf in that subdirectory, if that is what you want to do.

To suppress the 1 file(s) copied messae generate for each, simply append >nul to the above line.




回答2:


Just a small addition to @Magoo's answer;

in case the destination folders have spaces in their names, use double quotes like this: for /d %a in (d:\bootd\hello\2014*) do copy /y C:\EXAMPLE.DBF "%a\"

and as pointed out by @ian0411, in case source folder has spaces in its name, use double quotes like this: for /d %a in (d:\bootd\hello\2014*) do copy /y "C:\EXAMPLE.DBF" %a\



来源:https://stackoverflow.com/questions/30271432/copying-a-file-to-multiple-folders-in-the-same-directory

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