Solved

Copying directories

Posted on 2000-03-04
4
167 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
Comment Utility
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 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
Thanks, perfect
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

18 Experts available now in Live!

Get 1:1 Help Now