2014-01-20 32 views
1

我搜索並嘗試了用VBS刪除桌面上的特定文件的各種方法。如何使用VBS爲所有用戶刪除桌面文件?

我的代碼從來沒有錯誤 它只是不刪除文件。無論它是一個Delete.txt測試文件還是我真正想要移除的.url和.website文件。以下是一些幫助後的修改後的代碼。

Set Shell = CreateObject("WScript.Shell") 
Set FSO = CreateObject("Scripting.FileSystemObject") 
DesktopPath = Shell.SpecialFolders("Desktop") 
A = DesktopPath & "\Kronos Workforce Central(R).url" 
FSO.DeleteFile A 
B = DesktopPath & "\Kronos Workforce Central(R).website" 
FSO.DeleteFile B 

Line: 6

Char: 1

Error: File not found

Code: 800A0035

Source: Microsoft VBScript run time error

我的電腦不知道FSO是什麼?是否有另一種方法從桌面上刪除已知的文件?

回答

0

不是一個答案,但有證據爲「無報價參數的個數,以FSO方法」:

>> s = DesktopPath & "\Kronos Workforce Central(R).url" 
>> ss = qq(s) 
>> WScript.Echo s 
>> WScript.Echo ss 
>> WScript.Echo FSO.FileExists(s) 
>> WScript.Echo FSO.FileExists(ss) 
>> 
C:\Documents and Settings\eh\Desktop\Kronos Workforce Central(R).url 
"C:\Documents and Settings\eh\Desktop\Kronos Workforce Central(R).url" 
-1 
0 

以上應該證明文件C:\Documents and Settings\eh\Desktop\Kronos Workforce Central(R).url存在。這:

>> WScript.Echo FSO.FileExists(s) 
>> FSO.DeleteFile s 
>> WScript.Echo FSO.FileExists(s) 
>> 
-1 
0 
>> FSO.DeleteFile s 
>> 
Error Number:  53 
Error Description: File not found 

證明FSO.DeleteFile <FileSpecWithNoSpuriousQuotes>是消除(N現有的)文件的正確方式和當您嘗試扎普一個不存在的文件,你會得到一個「找不到文件」的錯誤。

如果.DeleteFile'不工作,沒有錯誤',那麼你有一個「On Error Resume Next」活動 - 總是一個壞主意。如果你沒有使用OERN並且沒有錯誤,那麼.DeleteFile刪除了一個文件 - 也許你看了一下錯誤的桌面?

相關問題