?
Solved

Copying directories

Posted on 2000-03-04
4
Medium Priority
?
210 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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