Copy a directory

How can I make a backup copy of a given directory?
neyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
Hi
use SHFileOperation API for thet

Hope this helps
0
VbmasterCommented:
I don't think inpras comment was much help unless you have the acutal code, so here it is..


  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 CopyAPI(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 FOF_FLAGS As Long
    Dim SHFileOp As SHFILEOPSTRUCT
 
    'Terminate the folder string with a pair of nulls
    sSource = sSource & Chr$(0) & Chr$(0)
 
    'Determine the user's options selected
    'FOF_FLAGS = BuildBrowseFlags()
 
    'Set up the options
    With SHFileOp
      .wFunc = FO_COPY
      .pFrom = sSource
      .pTo = sDestination
      .fFlags = FOF_NOCONFIRMATION
    End With
 
    'Perform the chosen copy or move operation
    CopyAPI = SHFileOperation(SHFileOp)

  End Function


You use the code with a simple class like this (this example copies everything inside the Helphelp directory on C:\ to D:\Backup.

  Call CopyAPI("C:\Helphelp\*", "D:\Backup\*")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vbWayneCommented:
'copy the contents of a directory to a directory or folder on a different drive
'copies files and folders seperately as they use different vehicles
'this example copies all of a:\ to c:\mydocuments


Public Sub CopyA()
    Dim FSO As Object
    On Error GoTo NOFSO
    Set FSO = CreateObject("Scripting.FileSystemObject")

    On Error Resume Next
    FSO.CopyFile "A:\*", "C:\My Documents\", True
    FSO.CopyFolder "A:\*", "C:\My Documents\", True
    Set FSO = Nothing
    Exit Sub
NOFSO:
    MsgBox "FSO CreateObject Failed"
End Sub

'vbWayne
0
neyAuthor Commented:
Thanks a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.