帮忙看一下这个程序并解释一下,谢谢

magicyangll 2008-03-28 10:44:05
这是一个文件夹备份的程序,请大家帮我再添上filelistbox 的代码以实现文件的备份,并帮我解释一下这段代码谢谢.
Dim fs As New FileSystemObject
Set fs = CreateObject("scripting.filesystemobject")
Dim origin_file As File, target_file As File, origin_fd As Folder, target_fd As Folder
Dim subfd As Folder, f As File, target_fileName As String
Set origin_fd = fs.GetFolder(origin_dir)
If Len(target_dir) = 3 Then
target_dir = Mid(target_dir, 1, 2)
End If
target_dir = target_dir & Mid(origin_dir, InStrRev(origin_dir, "\"))
If Not fs.FolderExists(target_dir) Then
fs.CreateFolder (target_dir)
End If
Set target_fd = fs.GetFolder(target_dir)
For Each origin_file In origin_fd.Files
target_fileName = target_dir & "\" & origin_file.Name
If Not fs.FileExists(target_fileName) Then
fs.CopyFile origin_file.Path, target_fileName
End If
Set target_file = fs.GetFile(target_fileName)
If target_file.DateLastModified <> origin_file.DateLastModified Then
fs.CopyFile origin_file.Path, target_fileName
End If
Next
For Each subfd In origin_fd.SubFolders
origin_dir = subfd.Path
Call overfolder(origin_dir, target_dir) '调用递归过程
Next: End Sub

  
...全文
54 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Sweetbaby722 2008-03-28
看看..
回复
cbm6666 2008-03-28
"我的是可以备份任何地方的文件夹"

Call BackUpFolder("c:\dll", "c:\dllbackup")

"c:\dll" 与 "c:\dllbackup" 这两个文件夹也是你随便可以自己选的,

你要加上文件,是为了选择 *.mp3 *.txt 等之类的吗?还是要一个一个文件来选择 ?

总之, 或许我不明白你真正想要达到的效果, 但看你的思路总觉得怪怪的.
回复
magicyangll 2008-03-28
我的是可以备份任何地方的文件夹的啊,不过我要在下面加个文件选择框,在里面的代码里加代码不知道怎么添加啊
回复
cbm6666 2008-03-28
更正: 多加了可能的 隐藏与系统文件的复制, 并免确认直接复盖.

'********************************* 第一种写法
Private Sub Command1_Click()
Call Shell("cmd /c xcopy " & "c:\dll\*.*/s/h/y " & "c:\dllbackup\", vbHide)
MsgBox "备份完成!"
End Sub


'********************************* 第二种写法
Private Sub Command1_Click()
Call BackUpFolder("c:\dll", "c:\dllbackup")
End Sub

Public Sub BackUpFolder(origin_fd$, target_fd$)
Call Shell("cmd /c xcopy " & origin_fd & "\*.*/s/h/y " & target_fd & "\", vbHide)
MsgBox "备份完成!"
End Sub
回复
cbm6666 2008-03-28
文件夹备份? 那么麻烦干啥 ? window 自带了 XCOPY

'********************************* 第一种写法
Private Sub Command1_Click()
Call Shell("cmd /c xcopy " & "c:\dll\*.*/s " & "c:\dllbackup\")
MsgBox "备份完成!"
End Sub


'********************************* 第二种写法
Private Sub Command1_Click()
Call BackUpFolder("c:\dll", "c:\dllbackup")
End Sub

Public Sub BackUpFolder(origin_fd$, target_fd$)
Call Shell("cmd /c xcopy " & origin_fd & "\*.*/s " & target_fd & "\")
MsgBox "备份完成!"
End Sub


回复
sstlwg 2008-03-28
恩啊
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2008-03-28 10:44
社区公告
暂无公告