简体   繁体   English

运行时错误Microsoft VBScript

[英]Runtime Error Microsoft VBScript

Help with a script. 帮助脚本。 Error: d: \\ learning \\ vbs \\ backup6.vbs (47, 9) Runtime Error Microsoft VBScript: Invalid call or argument procedure. 错误:d:\\ learning \\ vbs \\ backup6.vbs(47,9)运行时错误Microsoft VBScript:无效的调用或参数过程。 I can not understand why. 我不明白为什么。

Dim Fso
Dim Directory
Dim Modified
Dim Files
Dim source
Dim destination
Dim rar
Dim n

source = "d:\test\source\"
destination = "d:\test\destination\"
rar = "d:\learning\vbs\Rar.exe"
n = 3

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """rar"" a -agYYYY-MM-DD-HH-MM-SS " &destination& " " &source
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Directory = Fso.GetFolder(destination)
Set Files = Directory.Files
search_delete destination, n

Sub search_delete(str, n)
Dim strOldestFile
Dim dtmOldestDate
Dim count
Dim colFiles
Dim strFile

strOldestFile = ""
dtmOldestDate = Now
Set colFiles = Directory.Files

Do
    count = 0
    For Each objFiles in colFiles
        count = count + 1
        strFile = objFiles.Path
            dtmFileDate = objFiles.DateCreated
            If dtmFileDate < dtmOldestDate Then
                dtmOldestDate = dtmFileDate
                strOldestFile = strFile
            End If
    Next
    WScript.Echo(strOldestFile)

    If count > n Then
        Fso.DeleteFile strOldestFile
    End If  
    strOldestFile = ""

Loop While (count > n)

End Sub

error here in this line of code: Fso.DeleteFile (strOldestFile) 这行代码中的错误:Fso.DeleteFile(strOldestFile)

Your program's logic isn't such that strOldestFile will contain a filename when count > n . 程序的逻辑并不在于,当count > n时, strOldestFile将不包含文件名。

If you have a case where you have 3 files with ascending DateCreated time, then strOldestFile will never be set, yet Fso.DeleteFile will still be called. 如果你有,你有上升3个文件的情况下DateCreated的时间,然后strOldestFile将永远不会被设置,但Fso.DeleteFile仍然会被调用。

Visual Studio (all versions, up-to and including 2015) includes a VBScript debugger. Visual Studio(所有版本,包括2015年之前的版本)均包含VBScript调试器。 If you run a script using cscript //X //D $yourScriptFileName.vbs then it will prompt you to start VS and attach to the script host to step-through debug the script. 如果使用cscript //X //D $yourScriptFileName.vbs运行脚本,它将提示您启动VS并附加到脚本主机以逐步调试该脚本。

(Note that the //X //D command-line arguments really do have two forward-slashes) (请注意, //X //D命令行参数确实确实有两个正斜杠)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM