Option Explicit
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
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FO_COPY = &H2
Public Function ShellFileCopy(src As String, dest As String, _
Optional NoConfirm As Boolean = False) As Boolean
'PURPOSE: COPY FILES VIA SHELL API
'THIS DISPLAYS THE COPY PROGRESS DIALOG BOX
'PARAMETERS: src: Source File (FullPath)
'dest: Destination File (FullPath)
'NoConfirm (Optional): If set to
'true, no confirmation box
'is displayed when overwriting
'existing files, and no
'copy progress dialog box is
'displayed
'Returns (True if Successful, false otherwise)
'EXAMPLE:
'dim bSuccess as boolean
'bSuccess = ShellFileCopy ("C:\MyFile.txt", "D:\MyFile.txt")
Dim WinType_SFO As SHFILEOPSTRUCT
Dim lRet As Long
Dim lflags As Long
lflags = FOF_ALLOWUNDO
If NoConfirm Then lflags = lflags & FOF_NOCONFIRMATION
With WinType_SFO
.wFunc = FO_COPY
.pFrom = src
.pTo = dest
.fFlags = lflags
End With
lRet = SHFileOperation(WinType_SFO)
ShellFileCopy = (lRet = 0)
End Function作者: 5988143 时间: 2007-12-17 08:09
呵呵,謝謝分享~!作者: t小宝 时间: 2007-12-17 10:19
谢谢站长,学习先
能具体说下:
使用VBA或SHELL复制和用ShellFileCopy 函数复制具体有什么区别吗? 作者: Victor_Duane 时间: 2007-12-17 17:11
谢谢站长的分享,顶一下作者: rjacky 时间: 2007-12-17 18:02
我也想知道有什么区别,平时是用shell作者: tmtony 时间: 2007-12-17 18:26
SHELL 无法知道 复制是否完成,必须使用另一个API来检测 进程完成否
而以上API, 可返回成功与否的值作者: Grant 时间: 2007-12-17 22:41
已有,支持一个~API还支持批量复制,使用中的文件复制不出错,文件夹的复制删除等一系列操作作者: chaojianan 时间: 2009-9-27 11:10
谢谢站长。