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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying folders and files from one drive to another 2

Status
Not open for further replies.

dubble07

Programmer
May 8, 2002
12
CA
Anyone know the most efficient way possible to copy the contents of one directory to that of another including all nested files and folders.

thanks in advance!!

Steve
 
Steve,

Can you confirm that you're referring to wanting to do this "in code" ???

Otherwise, a SIMPLE "manual" method would be... opening TWO separate Explorer Windows and sizing them to both fit on the screen, and then copying/pasting from one to the other.

Not everyone knows this &quot;shortcut&quot;, so let me include it... to open Explorer, one can use <Window-key> E - i.e. HOLD DOWN the <Window-key> and hit &quot;E&quot;.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Thanks Dale for pointing out my oversight (and the interesting explorer tip).

The fact is, I am trying to do this in code and prior to doing it I wanted to see how others went about tackling this. What i'm trying to do is on a click event, fire the contents of one directory into another.

Thanks.

S
 
James, (or is that &quot;Sir James&quot;),

&quot;I'm back&quot; - with a solution...

The following routine should &quot;work like a charm&quot;, and in the &quot;blink of an eye&quot;. Actually, the user won't see it happen.

Sub BatchFile_Copy_01()
'runs batch file that copies files
'from c:\test1 to c:\test2
Shell &quot;C:\bat\copy_01.bat&quot;, vbHide
End Sub

Notes:

1) the &quot;copy_01.bat&quot; file contains the following:
@echo off
copy c:\test1\*.* c:\test2

2) this will over-write any existing files.

Hope this is what you were seeking. :) If you have any questions, don't hesitate to ask.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Private Sub CommandButton1_Click()
Dim oFSO As Object

Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
oFSO.CopyFile &quot;C:\test1\*.*&quot;, &quot;C:\test2\&quot;, True
Set oFSO = Nothing

MsgBox &quot;done&quot;
End Sub
 
thx guys - both ways work great, though they do ignore any nested folders. Is there a simple way to have all nested folders also copied up ?? Does the FileSystemObject support Directories?

thx

Sir James



 
Sir James,

(It's &quot;nice to know Royalty&quot;)

Sorry about not taking proper note of your original description - where you DID specify &quot;nested folders&quot;.

Here's the batch file line that WILL include nested folders.

xcopy c:\test1 /s c:\test2

As Justin correctly pointed out, you can attach this to any button. However I hadn't mentioned that, as I expected you might have other intentions such as attaching the code to some other routine that performs this backup in a &quot;transparent&quot; way.

Hope this helps. :)

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
>>Sorry about not taking proper note of your original description - where you DID specify &quot;nested folders&quot;.

same here

Code:
Dim oFSO As Object

Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
oFSO.CopyFolder &quot;C:\test1&quot;, &quot;C:\test2&quot;, True
Set oFSO = Nothing

MsgBox &quot;done&quot;
 
Justin,

While I knew the &quot;batch file method&quot;, I didn't know the &quot;scripting&quot; method - so THANKS for your contribution !!! It's obviously nice code to store in my &quot;library&quot;.

====> STAR. :)

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top