Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copying directories

Posted on 2000-03-04
4
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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