how can i copy a folder to many subfolders?

miketamp

Registered User.
Local time
Today, 08:49
Joined
Mar 30, 2005
Messages
22
Hi there
i would like to copy folders through forms
specifically i would like to copy the folder "C:\mike" to the subfolders of the "c:\test\"
how can i do that?

in the past i used the "copyfolder" function to do something like that:

' copy all folders from source to destination folder
Dim fso, dfol
Dim sfol As String
sfol = "C:\Program Files\diet\diets\Daily\*.*" ' source folder path
dfol = "C:\Program Files\diet\diets\Subcalorie\" ' destination folder path
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder sfol, dfol

But now the problem is that the destination folder has not a specific name and that it is not only one folder but all the folders included to the "test" folder

Can anyone please help me??
thanx...
 
Maybe you could incorporate something like this to what you have:
(Don't quote me on the syntax, it's the framework that's the point)

Code:
Dim fldr as Folder

For each fldr in dfol.SubFolders
   fso.CopyFolder sfol fldr
Next fldr
I think you will have to SET dfol = GetFolder("FolderPath")
Play with it, I think it's what you're looking for.
 
Hi Sergeant
Thanks for the reply
I use Access xp and it's not recocnize the "Dim fldr As folder"
specifically it don't recognize the "folder"
Can you please help me? may be you could write the code for me because i'm not as good as you think
Thanx...
 
miketamp said:
may be you could write the code for me because i'm not as good as you think
Thanx...
Me neither. (Don't tell anyone)
 
Here, I wrote this in AccessXP and it worked fine. (It only copies the CONTENTS of the source folder to the many destination folders.)
Code:
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:\mike")
    Set dfol = fso.GetFolder("c:\test\")
    For Each subfldr In dfol.SubFolders
        fso.CopyFolder sfol.Path, subfldr.Path
    Next subfldr
    Set sfol = Nothing
    Set dfol = Nothing
End Sub

Make sure you have "Microsoft Scripting Runtime" loaded in your Tools/References.

Let me know if it doesn't work for you.
 
Thanx you're the best
it work's fine. i wondered: is there any way that the user could see the windows copy progress bar (you know that bar that papers goes around )as long as the copy procedure need to be done and after the copy procedure is done and the progress bar disappear an msgbox "copy ok" appears
is this possible?
 
I'm sorry, I don't do progress indicators. Search the archives.
Message box is very easy...

MsgBox "File copy complete"
'right above the...
End Sub
 
You could update a message on the status bar to note which directory is being updated. Like this...

Code:
[COLOR=SeaGreen]'Place the "Public vStatusBar As Variant" at the top of a public class module, not a form module.[/COLOR]
Public vStatusBar As Variant
Code:
Private Sub Command0_Click()
    
    [COLOR=Blue]Application.SetOption "Show Status Bar", True[/COLOR]
    
    Dim fso As Scripting.FileSystemObject
    Dim dfol As Folder
    Dim sfol As Folder
    Dim subfldr As Folder
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set sfol = fso.GetFolder("c:\mike")
    Set dfol = fso.GetFolder("c:\test\")
    
    For Each subfldr In dfol.SubFolders
[COLOR=Blue]        vStatusBar = SysCmd(acSysCmdSetStatus, "Updating the " & subfldr.Path & " directory... please wait.")[/COLOR]
        fso.CopyFolder sfol.Path, subfldr.Path
    Next subfldr
    
    Set sfol = Nothing
    Set dfol = Nothing
    
    [COLOR=Blue]vStatusBar = SysCmd(acSysCmdClearStatus)[/COLOR]
    
End Sub
 
and how exactly can i Place the "Public vStatusBar As Variant" at the top of a public class module what is the steps?
 
If you do not already have a "public" [not a form] module then you need to click on the Modules tab, click the "new" button and then paste the Public vStatusBar As Variant at the top of your new public module.

Public declarations must appear at the top [above all subs and functions].
 
hi there
first of all
thanx for the reply and sorry for being so tiring
The steps that i've done are:
at the toggle folders view at the folder modules>right click>insert>class module>
in the new class module>paste "Public vStatusBar As Variant" under the "Option Compare Database"
after that,save it with what name???
is that steps correct?because it isn't work
under the folder modules there are already 3 modules but i don't know if there are public
How can i make it public and what name should have????
thanx...
 
They are public if they are in the 'modules' tab. You do not have to have a "class" module. My mistake in my previous wording. You can name your modules anything you want but give it some meaning.
 
Hi there
after a long time i have another problem with me project
with the code that you write for me i can copy the contents of the source folder to many subfolders.Now i want to copy the source folder include the subfolders to many folders.
for example:
i cane the "C:\source\" and the "C:\destination\folder1"
and "c:\destination\folder2".I would like to copythe source with the subfolders in the two folders of destination. Not only the contents of the source folder.
Can you please help me?
thanx...
 

Users who are viewing this thread

Back
Top Bottom