Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy single file to multiple directories

Status
Not open for further replies.

moogeboo

MIS
Aug 7, 2003
28
US
hello,

i have this simple script:

Dim fso
Dim path
Dim oFolder
Dim oSubFolder
Const OverwriteExisting = True

Set fso = createobject("Scripting.FileSystemObject")
File = "c:\test.txt"
Path = "c:\temp"
Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
fso.CopyFile File , OverwriteExisting
Next

What I want to do is copy that single file to every subfolder underneath the c:\temp folder. There are thousands and thousands of folders, and the subfolder depth may go as much as 40-50 folders deep within one folder. The script above copies the file to one subfolder level, but not anything beyond that. Can I make it so I can copy the file to as many subfolders as what I have?

Thank you,
Moogeboo
 
You have to use a recursive sub.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
>There are thousands and thousands of folders, and the subfolder depth may go as much as [blue]40-50 folders deep[/blue] within one folder
That's the sure way to asking for trouble one day or another!
 
I'm really curious as to why this is necessary? Can you clear out the temp folder first when the machine boots to reduce the number of folders? Your performance will totally suck as it is now.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top