1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_COPY = &H2
Private Const FOF_ALLOWUNDO = &H40
Private Sub Command1_Click()
'exemple
Call CopyFileWindowsWay(App.Path & "\denoxaut.732", App.Path & "\messanger\denoxaut.732")
End Sub
Public Sub CopyFileWindowsWay(SourceFile As String, DestinationFile As String)
Dim lngReturn As Long
Dim typFileOperation As SHFILEOPSTRUCT
With typFileOperation
.hWnd = 0
.wFunc = FO_COPY
.pFrom = SourceFile & vbNullChar & vbNullChar
.pTo = DestinationFile & vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
lngReturn = SHFileOperation(typFileOperation)
If lngReturn <> 0 Then
MsgBox Err.LastDllError, vbCritical Or vbOKOnly
Else
If typFileOperation.fAnyOperationsAborted = True Then
MsgBox "Operation Failed", vbCritical Or vbOKOnly
End If
End If
End Sub |
Partager