除了filecopy,还可用SHFileOperation,有进度的显示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 ' only used if FOF_SIMPLEPROGRESS End Type Const FO_COPY = &H2 Const FOF_SIMPLEPROGRESS = &H100 Private Sub Command1_Click() Dim fileOp As SHFILEOPSTRUCT Dim rtn As Long With fileOp
.hwnd = Me.hwnd .wFunc = FO_COPY .pFrom = "d:\backup\*.*" .pTo = "e:\" .fFlags = FOF_SIMPLEPROGRESS End With rtn = SHFileOperation(fileOp)
End Sub
偶的最后一问,如果共享目录设置了密码的话(win98),如何才可以访问并复制文件呢?
用WNetAddConnection 联接 代码如下: Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) 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 ' only used if FOF_SIMPLEPROGRESS End Type Const FO_COPY = &H2 Const FOF_SIMPLEPROGRESS = &H100 Private Sub Command1_Click() Dim fileOp As SHFILEOPSTRUCT Dim rtn As Long rtn = WNetAddConnection("\\mit002\temp", "111", "") '111为password With fileOp .hwnd = Me.hwnd .wFunc = FO_COPY .pFrom = "c:\a.txt" .pTo = "\\mit002\temp" .fFlags = FOF_SIMPLEPROGRESS End With rtn = SHFileOperation(fileOp)
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 ' only used if FOF_SIMPLEPROGRESS
End Type
Const FO_COPY = &H2
Const FOF_SIMPLEPROGRESS = &H100
Private Sub Command1_Click()
Dim fileOp As SHFILEOPSTRUCT
Dim rtn As Long
With fileOp
.hwnd = Me.hwnd
.wFunc = FO_COPY
.pFrom = "d:\backup\*.*"
.pTo = "e:\"
.fFlags = FOF_SIMPLEPROGRESS
End With
rtn = SHFileOperation(fileOp)
End Sub
代码如下:
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) 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 ' only used if FOF_SIMPLEPROGRESS
End Type
Const FO_COPY = &H2
Const FOF_SIMPLEPROGRESS = &H100
Private Sub Command1_Click()
Dim fileOp As SHFILEOPSTRUCT
Dim rtn As Long
rtn = WNetAddConnection("\\mit002\temp", "111", "") '111为password
With fileOp
.hwnd = Me.hwnd
.wFunc = FO_COPY
.pFrom = "c:\a.txt"
.pTo = "\\mit002\temp"
.fFlags = FOF_SIMPLEPROGRESS
End With
rtn = SHFileOperation(fileOp)
End Sub