Dim fso As New FileSystemObject fso.CopyFolder "d:\app\", "c:\" Set fso = Nothing
yoki: 不行啊,显示
User-defined type not defined
试试Private Sub Command1_Click() Dim fs As Object Set fs = CreateObject("Scripting.FileSystemObject") fs.CopyFolder "d:\app\", "c:\" End Sub
用文件系统模型filesystemobject,CopyFolder方法
Dim fs Set fs = CreateObject("Scripting.FileSystemObject") fs.CopyFolder "d:\app", "c:\"
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 BooleanDim 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
fso.CopyFolder "d:\app\", "c:\"
Set fso = Nothing
User-defined type not defined
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFolder "d:\app\", "c:\"
End Sub
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFolder "d:\app", "c:\"
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 BooleanDim 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