首页 > 解决方案 > 我在 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(权限被拒绝)。

标签: vbscript

解决方案


推荐阅读