copy a folder to many subfolders

miketamp

Registered User.
Local time
Today, 10:13
Joined
Mar 30, 2005
Messages
22
Hi there it's the second time that i'm trying to find answer to my problem. the first, nobody answer me.
Please help me it;s very important to me...
i have this code to copy the contents of the source folder to many subfolders:

Private Sub Command0_Click()
Dim fso As Scripting.FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Dim dfol As Folder
Dim sfol As Folder
Dim subfldr As Folder
Set sfol = fso.GetFolder("c:\source")
Set dfol = fso.GetFolder("c:\destination\")
For Each subfldr In dfol.SubFolders
fso.CopyFolder sfol.Path, subfldr.Path
Next subfldr
Set sfol = Nothing
Set dfol = Nothing
End Sub

Now i want to copy the source folder include the subfolders to many folders.
for example:
i have the "C:\source\" and the "C:\destination\folder1"
and "c:\destination\folder2".I would like to copy the source with the subfolders in the two folders of destination. Not only the contents of the source folder.
Can you please help me?
thanx...
 
Code:
Sub StartCopyingStuff()
   Dim fso As New Scripting.FileSystemObject
   Dim fsrc As Scripting.Folder
   Dim fdst As Scripting.Folder
   
   Set fsrc = fso.GetFolder("c:\YourSourceFolder")
   Set fdst = fso.GetFolder("c:\YourDestinationFolder")
   
   CopyStuff fso, fsrc, fdst

End Sub

Sub CopyStuff( _
   fso As Scripting.FileSystemObject, _
   fsrc As Scripting.Folder, _
   fdst As Scripting.Folder)
   Dim fLoop As Scripting.File
   Dim fdLoop As Scripting.Folder
   
   For Each fLoop In fsrc.Files
[COLOR=Green]      'copy all the files from the source folder to the destination folder[/COLOR]
      fso.CopyFile fLoop.Path, fdst.Path & "\"
   Next fLoop
   
   For Each fdLoop In fsrc.SubFolders
[COLOR=Green]      'copy each subfolder from the source folder to the destination folder[/COLOR]
      fso.CopyFolder fdLoop.Path, fdst.Path & "\"
[COLOR=Green]      'repeat this operation with the current subfolder (fdLoop) as the source,
      'and the newly copied subfolder as the destination[/COLOR]
      CopyStuff fso, fdLoop, fso.GetFolder(fdst.Path & "\" & fdLoop.Name)
   Next fdLoop
   
End Sub
 
Hi lagbolt
thanx for the reply, but the code you give me has exactly the same results with my code .please help me with this:
if we suppose that my source folder is :"source" and includes the subfolder "srcsub1" and "srcsub2" .if we suppose that the destination folder is the "destination"
i want to copy not only the contents of the "source" to "destination" but the "source" folder with his contents to destination which means that my new path must be:
destination\source\srcsub1
\srcsub2
And not destination\srcsub1
\srcsub2
The code you give me does the second.

Please help me…
 
try setting the destination path to "c:\destination\source"

easy hack around, i know :)
 
I don't really understand what you need. I wrote that code just to see what it would take. If you can tweak it to do exactly what you want, great!
 

Users who are viewing this thread

Back
Top Bottom