由于 "Bad file name or number" 无法删除,尽管文件可以打开

Cannot be deleted due to "Bad file name or number" although the file can be opened

Path = split(wscript.scriptFullName, wscript.scriptname)(0) 

上面指定下面使用的文件路径

CreateObject("wscript.shell").run ("""" & Path & "Document.txt""")

上面会打开"Document.txt",下面虽然路径一样,但是不会删除"Document.txt"

 CreateObject("Scripting.FileSystemObject").DeleteFile ("""" & Path & "Document.txt""")

错误信息是"Bad file name or number"。
如何修复错误?
文件名不应该是罪魁祸首,因为以下将删除 "Document.txt".

CreateObject("Scripting.FileSystemObject").DeleteFile ("E:\Testing\Document.txt")

将文件名作为参数传递给 DeleteFile 时,您不必在文件名周围添加双引号

现在您正在传递字符串

"E:\Testing\Document.txt"

方法DeleteFile需要没有双引号的路径

E:\Testing\Document.txt

正在将您的代码更改为

CreateObject("Scripting.FileSystemObject").DeleteFile Path & "Document.txt"

应该够了