我找不到VBS中的备份脚本出了什么问题

时间:2019-06-07 16:34:11

标签: vbscript

我的脚本可能非常简单,但是我没有发现任何错误。无论出于何种原因,我都可以复制每个文件夹而不是“文档”文件夹。我的脚本说找不到该路径。当我调整代码和文档“找到路径”时,然后出现“权限被拒绝”错误。仅在“文档”文件夹中存在此问题。我的代码在下面,我正在寻求有关如何解决此问题的帮助。

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(拒绝权限)。

0 个答案:

没有答案
相关问题