Solved

Copying directories

Posted on 2000-03-04
4
182 Views
Last Modified: 2010-05-02
How do I copy complete directories (Including files in subdirectories and retaining directory structure). There must a better method than mkdir , and filecopy - very tedious.
0
Comment
Question by:dcollis
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
ID: 2582920
Add this to a module:

  Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
  End Type
  Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  Public Function SysCopy(sSource As String, sDestination As String) As Long
    Const FO_COPY = &H2
    Const FO_MOVE = &H1
    Const FOF_SILENT = &H4
    Const FOF_RENAMEONCOLLISION = &H8
    Const FOF_NOCONFIRMATION = &H10
    Const FOF_SIMPLEPROGRESS = &H100
    Const FOF_ALLOWUNDO = &H40
    Dim SHFileOp As SHFILEOPSTRUCT
    sSource = sSource & Chr$(0) & Chr$(0)
    With SHFileOp
      .wFunc = FO_COPY
      .pFrom = sSource
      .pTo = sDestination
      .fFlags = FOF_NOCONFIRMATION
    End With
    SysCopy = SHFileOperation(SHFileOp)
  End Function


Then you can call it like this:

   SysCopy "C:\temp\*","c:\nottemp"


If the destination doesn't exist, it will ask you to create it...


Cheers!®©
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2582941
You can use the File System Object for this. Set a reference to «Microsoft scripting runtime» and type this:
FileSystemObject.CopyFolder "c:\mydocuments\letters\*", "c:\tempfolder\"
0
 

Author Comment

by:dcollis
ID: 2586885
Thanks, perfect
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2587271
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

815 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

8 Experts available now in Live!

Get 1:1 Help Now