【发布时间】:2014-12-17 20:10:52
【问题描述】:
我想备份所有文件和文件夹。
例如:我有 2 个文件和一个位于 D:\Temp 文件夹中的文件夹。
我在同一文件夹中还有一个名为“Backup”的文件夹,即 D:\Temp\
所以我想将除备份文件夹之外的所有文件和文件夹移动到 Access VBA 中的备份文件夹。这可能吗?
这是我迄今为止从 Ron 的代码中尝试过的。
我尝试从一个文件夹移动到临时文件夹,然后从该文件夹移动到我的原始文件夹,如下所示。但我遇到了错误。
savepath = "d:\test\"
savepath2 = "d:\temp\"
savepath1 = "d:\test\Archieve\"
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = savepath '<< Change
ToPath = savepath2 '<< Change
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.moveFolder Source:=FromPath, Destination:=ToPath
If Not DirExists(savepath) Then
MkDir (savepath)
End If
If Not DirExists(savepath1) Then
MkDir (savepath1)
End If
FromPath = savepath2 '<< Change
ToPath = savepath1 '<< Change
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.moveFolder Source:=FromPath, Destination:=ToPath
【问题讨论】: