Mik Mak
asked on
VBA folder copy - destination folder duplicates
In Access 2010/2013 VBA I'm using this function as a way to copy files in a foider to another folder - and first time run it works fine - but second time run, if the folder already exists, the target folder is then created inside the already existing target folder - I cannot figure out whats wrong :) ?
VBCopyFolder "H:\Tools\PH\", "C:\Users\Michael\AppData\ Roaming\PH ", True
VBCopyFolder "H:\Tools\PH\", "C:\Users\Michael\AppData\
Private Const FO_MOVE As Long = &H1
Private Const FO_COPY As Long = &H2
Private Const FO_DELETE As Long = &H3
Private Const FO_RENAME As Long = &H4
Private Const FOF_MULTIDESTFILES As Long = &H1
Private Const FOF_CONFIRMMOUSE As Long = &H2
Private Const FOF_SILENT As Long = &H4
Private Const FOF_RENAMEONCOLLISION As Long = &H8
Private Const FOF_NOCONFIRMATION As Long = &H10
Private Const FOF_WANTMAPPINGHANDLE As Long = &H20
Private Const FOF_CREATEPROGRESSDLG As Long = &H0
Private Const FOF_ALLOWUNDO As Long = &H40
Private Const FOF_FILESONLY As Long = &H80
Private Const FOF_SIMPLEPROGRESS As Long = &H100
Private Const FOF_NOCONFIRMMKDIR As Long = &H200
Public Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String, bOverWrite As Boolean) ', bAllowUndo As Boolean)
Dim op As SHFILEOPSTRUCT
Dim lngFlags As Long
With op
.wFunc = FO_COPY
.pTo = strTarget
.pFrom = strSource
If bOverWrite = True Then
lngFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION
Else
lngFlags = FOF_SIMPLEPROGRESS
End If
.fFlags = lngFlags
End With
SHFileOperation op
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window