我正在尝试使用以下VB脚本从Windows Temp文件夹中删除所有以字符串“ MyApp”开头的日志文件。
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
Run Code Online (Sandbox Code Playgroud)
似乎以下检查失败:
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
Run Code Online (Sandbox Code Playgroud)
我认为VBScript不支持使用通配符的FileExists。更好的选择是仅抑制删除操作中的错误并运行DeleteFile命令。
On error resume next
objFSO.DeleteFile "C:\Documents and Settings\guest\Local Settings\Temp\MyApp.*", True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15504 次 |
| 最近记录: |