1

它在 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 中删除它

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
4

2 回答 2

1

This should do it:

wshShell.Run "del """ & objFile.Path & """", 1, True  
于 2011-05-21T09:50:50.287 回答
1

路径中有一个空格,所以它应该用双引号括起来,比如"del \"" & objFile.Path & "\"",或者任何用于转义的 VB 语法。

于 2011-05-20T15:32:23.383 回答