vbscript - 我在 VBS 中找不到我的备份脚本有什么问题
问题描述
我的脚本可能过于简单复杂,但我没有发现代码有任何问题。无论出于何种原因,我都可以复制每个文件夹而不是我的 Documents 文件夹。我的脚本说找不到路径。当我调整代码和文档“找到路径”时,我会收到“权限被拒绝”错误。此问题仅出现在 Documents 文件夹中。我的代码在下面,我正在寻求有关如何解决此问题的帮助。
Option Explicit
Dim oShell, oFSO
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Const Overwrite = True
Dim strHomeFolder
Dim usersName
Dim UserProfile
strHomeFolder = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
usersName = oShell.ExpandEnvironmentStrings("%USERNAME%")
Sub DataBackup
UserProfile = strHomeFolder & "\"
Dim Desktop, Documents, Downloads, Favorites, Pictures, Videos, Music,
Dim nDocuments, n1Documents
Documents = UserProfile & "Documents"
'nDocuments = "C:\Users\" + usersName + "\" + "Documents"+ "\" - " Test"
'n1Documents = "C:\Users\user.profile.name\Documents\" - "Test"
Desktop = UserProfile & "\Desktop"
Downloads = UserProfile & "\Downloads"
Favorites = UserProfile & "\Favorites"
Pictures = UserProfile & "\Pictures"
Videos = UserProfile & "\Videos"
Music = UserProfile & "\Music"
Dim dtmValue, strDate, strTime
dtmValue = Now()
'Assuming that you are creating these folders in C:\
strDate = "C:\MyBackup" & "_" & Month(dtmValue) & "-" & Day(dtmValue) & "-" & Year(dtmValue)
strTime = strDate & "_" & Hour(dtmValue) & "." & Minute(dtmValue)
Dim DestTimeStampFolder
DestTimeStampFolder = StrTime
oFSO.CreateFolder DestTimeStampFolder
MsgBox "check if folder exists!"
If Not oFSO.FolderExists(DestTimeStampFolder) Then
Set DestTimeStampFolder = oFSO.CreateFolder(DestTimeStampFolder)
End If
On Error Resume Next
MsgBox DestTimeStampFolder & "\Documents"
oFSO.CopyFolder Documents, DestTimeStampFolder & "\Documents", Overwrite
'oFSO.CopyFolder nDocuments, DestTimeStampFolder & "\Documents", Overwrite - ' "Used for Testing"
'oFSO.CopyFolder n1Documents, DestTimeStampFolder & "\Documents", Overwrite - ' "Used for Testing"
If Err Then
WScript.Echo "Error # " & Err.Number
WScript.Echo Err.Description
WScript.Quit 1
End If
End Sub
我的调试代码给了我一个错误代码 70(找不到路径)和 76(权限被拒绝)。
解决方案
推荐阅读
- java - 在 Java 中将数据读入二叉搜索树
- azure - Azure 授权:REST API 中的范围参数是什么?
- firebase - 尽管令牌过期时间为 1 小时,如何让我的 Firebase 应用程序的用户保持登录状态
- ruby-on-rails - Ruby:在没有 Ruby on rails 框架(Jekyll 插件)的情况下参数化字符串
- api - 贝宝多卖家中的无限循环
- pandas - 熊猫十分位排名
- python - 如何使用 Python Flask 和 Axios/ReactJs 发送用户输入附件?
- javascript - 如何从注入 Svelte 应用程序的网页获取和设置 Svelte 商店值?
- pytorch - Colab TPU 在创建模型时崩溃并重新启动
- visual-studio - “找不到参考组件‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’。” 对于所有在 VS2017 中的参考资料