Link to home
Start Free TrialLog in
Avatar of shizon
shizon

asked on

Mirror Copy Directory and SubDirectories

Windows 2000 Peer to Peer Network

I have a network drive (server c drive) mapped to "F" on a workstation.

I would like to be able to copy 5 directories and their subdirectories (along with any files inside) from the server C-drive (F) to the local workstation c-drive in case the server fails.

Basically, I tried copy folder and it works fine unless one of the files in the directory is opened exclusively.  Then it bails of course.

I need to be able to copy the entire directory's contents and skip the files that are "in use".
Avatar of vinnyd79
vinnyd79

try this: (make sure you edit the .pFrom line to reflect your server name or ip address)

Option Explicit
Private Declare Function SHFileOperation Lib "shell32.dll" _
   Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FO_MOVE = &H1
Const FO_RENAME = &H4
Const FOF_ALLOWUNDO = &H40
Const FOF_SILENT = &H4
Const FOF_NOCONFIRMATION = &H10
Const FOF_RENAMEONCOLLISION = &H8
Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_FILESONLY = &H80

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 Sub Command1_Click()
Dim result As Long, fileop As SHFILEOPSTRUCT
With fileop
       .hwnd = Me.hwnd
       .wFunc = FO_COPY
       .pFrom = "\\<server name or ip>\C$\Somefolder\*" & vbNullChar & vbNullChar
       .pTo = "D:\MyNewfolder\" & vbNullChar & vbNullChar
       .fFlags = FOF_NOCONFIRMMKDIR
End With
result = SHFileOperation(fileop)
If result <> 0 Then
       ' Operation failed
       MsgBox Err.LastDllError
End If
End Sub
Avatar of shizon

ASKER

It still kicks me out when I hit a file that is opened exclusively by another program instead of just skipping that file and continuing on.

Thanks though
ASKER CERTIFIED SOLUTION
Avatar of TigerZhao
TigerZhao

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Private Sub Command1_Click()
Dim Src As String
Dim Dest As String
Src = "\\<server name or ip>\<sharename>\C$\Somefolder\*.*"
Dest = "C:\NewFolder"
Shell "cmd.exe /c xcopy " & Src & Space(1) & Dest & " /h/i/c/k/e/r", vbHide
End Sub
Avatar of shizon

ASKER

I actually figured it out yesterday, but did it the same way.

Thanks