• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Copy a directory

How can I make a backup copy of a given directory?
0
ney
Asked:
ney
1 Solution
 
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now