gpt4 book ai didi

vbscript - 如何使用 VBScript 删除临时文件夹中以特定名称开头的所有文件

转载 作者:行者123 更新时间:2023-12-04 00:45:13 24 4
gpt4 key购买 nike

我正在尝试使用以下 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

似乎以下检查失败了:

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

最佳答案

我认为 VBScript 不支持使用通配符FileExists。更好的选择是只抑制删除错误并运行 DeleteFile 命令。

 On error resume next

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

关于vbscript - 如何使用 VBScript 删除临时文件夹中以特定名称开头的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11742848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com