Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private 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 String '仅用于 FOF_SIMPLEPROGRESS
End Type
Private Const FO_COPY = &H2 '复制
'复制文件
Private Function CopyFile(ByVal sFileFrom As String, ByVal sFileTo As String) As Boolean
Dim fo As SHFILEOPSTRUCT
With fo
.pFrom = sFileFrom
.pTo = sFileTo
.wFunc = FO_COPY
End With
CopyFile = Not (CBool(SHFileOperation(fo)))
End Function
'调用时:
Private Sub Command1_Click()
Debug.Print CopyFile("f:\Music\she", "f:\a")
End Sub