4

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.

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
VicT
  • 35
  • 1
  • 1
  • 2

2 Answers2

4

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.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Magoo you are legitimately rad! By append do you mean the script should look like: for /d %a in (d:\bootd\hello\2014*) do copy /y C:\EXAMPLE.DBF %a\ >null ? – VicT May 16 '15 at 19:22
  • I tried this out and was very hopeful...although no matter what I try the "EXAMPLE.DBF" can never be found. This is definitely pathed correctly. Am I missing something? – VicT May 16 '15 at 20:02
  • @ Magoo Thank you VERY VERY much Magoo...this is such a time saver... If you have time I have another question if you could hep me out: I need to run an executable on all of the dated sub-directories once I input the files... I would usually do this by a cmd like this: d:\bootd\hello\executables\example.exe /date 20140131 **The problem with this is that I can only execute the executable on one folder at a time** – VicT May 16 '15 at 20:40
  • The `>nul` directs any outout to *nowhere* (it's designed that way) Note however that there;s only one `l` - with two, it will create a file named `null`. The extension question - it's quite easy, but unrelate to your oginal question. The object of SO is to generate a databse of questions and answers, so you should ask a further question for FREE – Magoo May 17 '15 at 02:10
  • Thanks @Magoo ... http://stackoverflow.com/questions/30283066/how-do-you-run-an-executable-on-multiple-folders – VicT May 17 '15 at 03:29
  • In case if the name of the source folder has spaces, you can use double quotes like this to do the work: FOR /d %A IN (D:\bootd\hello\2014*) DO xcopy /y "C:\Program Files\EXAMPLE.DBF" %a\ – ian0411 Feb 16 '17 at 15:44
1

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\