API
BOOL CopyFile(
LPCTSTR lpExistingFileName, // name of an existing file
LPCTSTR lpNewFileName, // name of new file
BOOL bFailIfExists // operation if file exists
);
BOOL CopyFile(
LPCTSTR lpExistingFileName, // name of an existing file
LPCTSTR lpNewFileName, // name of new file
BOOL bFailIfExists // operation if file exists
);
msgbox("请使用windows自身的复制文件功能")
当然是指运行最快to:jjx()
msgbox("我要用VB编写")
Declare Function CopyFile Lib ""kernel32"" Alias ""CopyFileA"" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
说明
复制文件。与vb的filecopy命令相似
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpExistingFileName String,源文件名
lpNewFileName String,目标文件名
bFailIfExists Long,如果设为TRUE(非零),那么一旦目标文件已经存在,则函数调用会失败。否则目标文件被改写
声明:
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_ALLOWUNDO = &H40Public Function CopyFile(sFrom As String, sTo As String)
'** Description:
'** Copy file
On Error GoTo CopyError
Dim SHFO As SHFILEOPSTRUCT
With SHFO
.wFunc = FO_COPY 'Set copy metod
.pFrom = sFrom 'Set from filename
.pTo = sTo 'Set to filename
End With
SHFileOperation SHFO 'Copy file
exit functionCopyError:
msgbox err.description
End Function上面的程序没有调试过,你自己测试一下吧 :)
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End TypePrivate Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_ALLOWUNDO = &H40Public Function CopyFile(sFrom As String, sTo As String)
'** Description:
'** Copy file
On Error GoTo CopyError
Dim SHFO As SHFILEOPSTRUCT
With SHFO
.wFunc = FO_COPY 'Set copy metod
.pFrom = sFrom 'Set from filename
.pTo = sTo 'Set to filename
End With
SHFileOperation SHFO 'Copy file
exit functionCopyError:
msgbox err.descriptionEnd Function