Solved

Copy singel file to multiple directories

Posted on 2004-04-29
12
728 Views
Last Modified: 2008-12-01
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?
0
Comment
Question by:Veggers
  • 4
  • 4
  • 2
  • +1
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10948186
How are the directories laid out?  Are these all the subfolders in one folder, or are they scattered?
0
 
LVL 1

Author Comment

by:Veggers
ID: 10948311
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.
0
 
LVL 1

Expert Comment

by:mightypeo
ID: 10948435
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10948472
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
0
 
LVL 1

Author Comment

by:Veggers
ID: 10949132
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?
0
 
LVL 1

Expert Comment

by:mightypeo
ID: 10949168
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.

0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 67

Expert Comment

by:sirbounty
ID: 10949489
Try enclosing the last %a in quotes (due to long file names)
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 25 total points
ID: 10950719
FOR /R %a in (.) do copy .\myFile.txt "%a"

should do it..
0
 
LVL 83

Accepted Solution

by:
oBdA earned 100 total points
ID: 10957089
This will copy the specified file only to the bottoms/leaves of a given directory tree. Simply adjust the settings at the beginning.
Note that the script is currently in test mode, it will only display the copy command it would otherwise issue, so that you can check if it works for you.

===8<----[Copy2Bottom.cmd]----
@echo off
setlocal
:: *** Directory to start in:
set RootDir=D:\Test
:: *** File to be copied:
set CopyFile=D:\Temp\test.txt

for /f "delims=" %%a in ('dir /s /b /a:d "%RootDir%"') do (
  set SubDir=%%a
  call :process
)
goto leave

:process
set TestDir=
for /f "delims=" %%a in ('dir /b /a:d "%SubDir%"') do set TestDir=%%a
if not "%TestDir%"=="" goto :eof
:: *** We're at the bottom of a directory tree:
echo Copying to "%SubDir%" ...
:: *** Test mode: remove the "ECHO" at the beginning of the next line to "arm" the script:
ECHO copy "%CopyFile%" "%SubDir%"

goto :eof

:leave
echo Done.
===8<----[Copy2Bottom.cmd]----
0
 
LVL 1

Author Comment

by:Veggers
ID: 10958271
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?

0
 
LVL 83

Expert Comment

by:oBdA
ID: 10958532
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.
0
 
LVL 1

Author Comment

by:Veggers
ID: 10958741
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now