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".
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".
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
Thanks though
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub Command1_Click()
Dim Src As String
Dim Dest As String
Src = "\\<server name or ip>\<sharename>\C$\Somefol
Dest = "C:\NewFolder"
Shell "cmd.exe /c xcopy " & Src & Space(1) & Dest & " /h/i/c/k/e/r", vbHide
End Sub
ASKER
I actually figured it out yesterday, but did it the same way.
Thanks
Thanks
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