Option Explicit
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 String '只有在 FOF_SIMPLEPROGRESS 时用
End Type
Public Declare Function SHFileOperation Lib _
"shell32.dll" Alias "SHFileOperationA" (lpFileOp _
As SHFILEOPSTRUCT) As Long 'api函数SHFileOperation 的声明
'wFunc 常数
'FO_COPY 把 pFrom 文件拷贝到 pTo。
Public Const FO_COPY = &H2
'fFlag 常数
'FOF_ALLOWUNDO 允许 Undo 。
Public Const FOF_ALLOWUNDO = &H40
'FOF_NOCONFIRMATION 不显示系统确认对话框。
Public Const FOF_NOCONFIRMATION = &H10
'FOF_NOCONFIRMMKDIR 不提示是否新建目录。
Public Const FOF_NOCONFIRMMKDIR = &H200
'FOF_SILENT 不显示进度对话框
Public Const FOF_SILENT = &H4
'以上皆为SHFileOperation 需要的变量的声明,固定声明格式直接拿来使用
调用时
Private Function CopyFileApi(RemoteFolder As String, LocalDir As String)
On Error GoTo Error
Dim SHFileOp As SHFILEOPSTRUCT
SHFileOp.wFunc = FO_COPY
SHFileOp.pFrom = RemoteFolder
SHFileOp.pTo = LocalDir
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR
Call SHFileOperation(SHFileOp)
Exit Function
Error:
MsgBox Err.Description
End Function
2 个解决方案
#1
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR + FOF_NOCONFIRMATION
#2
噢,我试验一下
#1
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR + FOF_NOCONFIRMATION
#2
噢,我试验一下