Private Sub cmdCopy_Click() File1.Path = "d:\aa" '假如要复制D盘AA目录下的所有文件
For i = 0 To File1.ListCount - 1 '假如将D盘AA目录下的所有文件复制到D盘BB目录下 FileCopy File1.Path & "\" & File1.List(i), "d:\bb\" & File1.List(i) Next End Sub
Dim OFSO As New Scripting.FileSystemObject Dim ObjFile As Scripting.File Private Sub FileCopy(ByVal strSource As String, ByVal strdestin As String) If Right(strSource, 1) <> "\" Then strSource = strSource & "\" If Right(strdestin, 1) <> "\" Then strdestin = strdestin & "\" For Each ObjFile In OFSO.GetFolder(strSource).Files If OFSO.FileExists(strdestin & ObjFile.Name) Then OFSO.Delete Filestrdestin & ObjFile.Name End If OFSO.CopyFile strSource & ObjFile, strdestin Next End Sub
cuizm(射天狼) 你好能否不用file控件,即纯粹的后台操作
dreamreality(追梦) 你好运行你的代码,系统提示此句 Dim OFSO As New Scripting.FileSystemObject编译错误: 用户定义类型未定义
“工程”->“引用”,选中“microsoft scripting runtime”
标准方法(只用内部功能)s=strsource s0=strtag s1=dir(s & "\*.*") do while s1<>"" if left(s1,1)<>"." then filecopy s & "\" & s1 , s0 & "\" & s1 endif s1=dir loop
File1.Path = "d:\aa" '假如要复制D盘AA目录下的所有文件
For i = 0 To File1.ListCount - 1
'假如将D盘AA目录下的所有文件复制到D盘BB目录下
FileCopy File1.Path & "\" & File1.List(i), "d:\bb\" & File1.List(i)
Next
End Sub
Dim ObjFile As Scripting.File
Private Sub FileCopy(ByVal strSource As String, ByVal strdestin As String)
If Right(strSource, 1) <> "\" Then strSource = strSource & "\"
If Right(strdestin, 1) <> "\" Then strdestin = strdestin & "\"
For Each ObjFile In OFSO.GetFolder(strSource).Files
If OFSO.FileExists(strdestin & ObjFile.Name) Then
OFSO.Delete Filestrdestin & ObjFile.Name
End If
OFSO.CopyFile strSource & ObjFile, strdestin
Next
End Sub
Dim OFSO As New Scripting.FileSystemObject编译错误:
用户定义类型未定义
s0=strtag
s1=dir(s & "\*.*")
do while s1<>""
if left(s1,1)<>"." then
filecopy s & "\" & s1 , s0 & "\" & s1
endif
s1=dir
loop