Solved

Copying directories

Posted on 2000-03-04
4
175 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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

920 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

11 Experts available now in Live!

Get 1:1 Help Now