3

以下の VB スクリプトを使用して、文字列「MyApp」で始まるすべてのログ ファイルを Windows Temp フォルダから削除しようとしています。

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

if objFSO.FolderExists("C:\Documents and Settings\guest\MyApp") Then
          set folder = objFSO.getFolder("C:\Documents and Settings\guest\MyApp") 

if folder.files.Count <> 0 then 
    objFSO.DeleteFile "C:\Documents and Settings\guest\MyApp\*.*", True
end if 
          objFSO.DeleteFolder "C:\Documents and Settings\guest\MyApp", True
end if

<!--  The below code is not deleting the files which starts with the name "Mpp.023648011.log"   -->

if(objFSO.FileExists("C:\Documents and Settings\guest\Local Settings\Temp\MyApp.*")) Then
    objFSO.DeleteFile "C:\Documents and Settings\guest\Local Settings\Temp\MyApp.*", True
end if

以下のチェックが失敗しているようです:

if(objFSO.FileExists("C:\Documents and Settings\guest\Local Settings\Temp\MyApp.*"))

前もって感謝します。

エラーメッセージを抑制してDeleteFileを実行する方法を見つけました。それは私のために働いた。

     On error resume next

     objFSO.DeleteFile "C:\Documents and Settings\guest\Local Settings\Temp\MyApp.*", True
4

1 に答える 1

5

VBScript は、ワイルドカードを使用したFileExistsをサポートしていないと思います。より良いオプションは、削除によるエラーを抑制し、DeleteFile コマンドを実行することです。

 On error resume next

 objFSO.DeleteFile "C:\Documents and Settings\guest\Local Settings\Temp\MyApp.*", True 
于 2012-08-02T21:52:43.893 に答える