Link to home
Start Free TrialLog in
Avatar of Veggers
Veggers

asked on

Copy singel file to multiple directories

I have a file that i'd like to copy to thousands of different folders, obviously this process would be very time consuming, so i'm looking for either a program that allows me to select lots of folders at once and send the file to these folders, or perhaps a command that will work in the command prompt. I'd also like to be able to send a single folder to multiple folders.

Anyone know a way to do this?
Avatar of sirbounty
sirbounty
Flag of United States of America image

How are the directories laid out?  Are these all the subfolders in one folder, or are they scattered?
Avatar of Veggers
Veggers

ASKER

They are a little scattered, there is one main folder, and the folders go four directories deep (if that makes sense; folder, in a folder, in a folder, in a folder). It doesn't matter if the file ends up in all the folders, starting from the root folder, as long as the file makes its way to the folders at the bottom of the tree. Hopefully this makes sense.
Generate a list of the target folders in a text file (i.e. targetdirs.txt)
Then use the for command (builtin) to copy your file, with a line like this (this assumes that the directories are one per line in targetdirs.txt)
for /F %i in (targetdirs.txt) do copy <name of file> %i\<name of file at destination>

dir /b /s [folder] >targetdirs.txt

can be used to generate the file with the target directories
Well, if it doesn't matter if they go in all of them, then this should work:

Assuming the file - myfile.txt is in C:\MyFolder and you want it in Folder1, Folder2, Folder3, Folder4, Folder1\Folder11, Folder2\Folder21, etc...??

From the command line (start->Run->CMD)

FOR /R %a in (.) do copy .\myFile.txt %a
Avatar of Veggers

ASKER

mightypeo,
This would be useful, but it would take a long time to make a list of the target directories, so is not really visable.

sirbounty,
Tried the command, not sure if its me doing it wrong, but for each folder i get the following error message:

F:\folder>copy .\awe.txt F:\folder\New Folder (3)\New Folder (2)\.
The syntax of the command is incorrect.

The command i used was to test it, using a file called awe.txt, copied to some arbitary new folders. The line i typed was:

F:\folder> FOR /R %a in (.) do copy .\awe.txt %a

It was successful in copying to only the root folder, i.e. F:\folder.

Any suggestions?
how many folders are we talking about ? have you tried the dir /s /b command. ? I was able to list a few thousand directories on one of our servers that way.

Try enclosing the last %a in quotes (due to long file names)
SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Veggers

ASKER

mightypeo,
This will list them, but is there any way to copy the text the command prompt produces (probably my lack of knowledge)

sirbounty,
Thank you, this did work, however if it is possible to copy to the root directories as oBdA has described, this would be possible.

oBdA,
Tried this script, after the 'call process' line, i get the following error message:
Invalid attempt to call batch label outside of batch script
Any ideas why?

Something went wrong with copy and paste. Copy the complete content between, but excluding the cut lines ("===8<----[Copy2Bottom.cmd]----"), save it someplace as Copy2Bottom.cmd (or whatever you want to name it).
Then adjust the root directory and the file to be copied.
Try again.
If it shows the proper commands, remove the "ECHO" where indicated.
Avatar of Veggers

ASKER

Your right, i was doing it wrong! The script woked perfectly, thanks for all the help. I owe you one, this should cut down my work load significantly.

Thanks for all the help guys.