我无法删除桌面上的文件(所有用户),但我可以在没有脚本的情况下删除
它在 wshShell.Run 上崩溃。
您可以看到我运行了 WScript.Echo,它确实打印了文件名的位置。当我运行它时,它说“系统找不到指定的文件”
我尝试了 objFile.delete 但它说权限被拒绝。如果我在命令提示符中执行“del”,它就会起作用。
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
WScript.Echo objFile.Name
WScript.Echo objFile.Path
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshShell.Run "del " & objFile.Path, 1, True
Set wshShell = Nothing
End If
Next
输出
Lotus Notes 8.5.lnk
C:\Users\Public\Desktop\Lotus Notes 8.5.lnk
(null) (79, 3) : (null)
------------------ 更新 ------------------ 如果它位于用户桌面(而不是 AllUsersDesktop)上,则以下内容可以完美运行。我试图从 AllUsersDesktop 中删除它
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
objFile.Delete
End If
Next
应用以下代码后,我收到此错误
Lotus Notes 8.5.lnk
C:\Users\Public\Desktop\Lotus Notes 8.5.lnk
(null) (81, 3) : (null)
代码:(截至 5/23 更新)
Set objShell = CreateObject("WScript.Shell")
strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strCurrentDirectory)
Set objFolderItem = objFolder.Self
Set objFolder = objFS.GetFolder(strCurrentDirectory)
Set colFiles = objFolder.Files
Set objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = True
objRE.Pattern = "notes"
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
WScript.Echo objFile.Name
WScript.Echo objFile.Path
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshShell.Run "del """ & objFile.Path & """", 1, True
Set wshShell = Nothing
End If
Next
It crashes on wshShell.Run.
You can see that I run a WScript.Echo and it does print the location of the file name. When I run it, it says the "The system could not find the file specified"
I tried objFile.delete but it says Permission denied. If i perform "del " in the command prompt, it works.
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
WScript.Echo objFile.Name
WScript.Echo objFile.Path
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshShell.Run "del " & objFile.Path, 1, True
Set wshShell = Nothing
End If
Next
Output
Lotus Notes 8.5.lnk
C:\Users\Public\Desktop\Lotus Notes 8.5.lnk
(null) (79, 3) : (null)
------------------ UPDATE ------------------
The following works perfectly if it's on the Users Desktop (not the AllUsersDesktop). I'm trying to delete it from the AllUsersDesktop
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
objFile.Delete
End If
Next
After applying the following code, I get this error
Lotus Notes 8.5.lnk
C:\Users\Public\Desktop\Lotus Notes 8.5.lnk
(null) (81, 3) : (null)
Code: (updated as of 5/23)
Set objShell = CreateObject("WScript.Shell")
strCurrentDirectory = objShell.SpecialFolders("AllUsersDesktop")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strCurrentDirectory)
Set objFolderItem = objFolder.Self
Set objFolder = objFS.GetFolder(strCurrentDirectory)
Set colFiles = objFolder.Files
Set objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = True
objRE.Pattern = "notes"
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
WScript.Echo objFile.Name
WScript.Echo objFile.Path
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshShell.Run "del """ & objFile.Path & """", 1, True
Set wshShell = Nothing
End If
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以做到:
This should do it:
该路径中有一个空格,因此应该用双引号引起来,例如
"del \"" & objFile.Path & "\""
,或者任何用于转义的 VB 语法。The path has a space in it, so it should be enclosed in double quotes, something like
"del \"" & objFile.Path & "\""
, or whatever VB syntax for escaping is.