VBScript删除文件夹

时间:2017-09-26 05:05:35

标签: vbscript

我正在使用以下代码删除该文件夹,因为它被其他应用程序使用我收到错误:

  

权限被拒绝 - 无法删除文件夹

我需要一个代码来检查该文件夹是否被其他应用程序使用,如果是这样,请删除该进程,然后删除该文件夹。

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Users\x")
'delete all files in root folder
For Each f In folder.Files
  On Error Resume Next
  name = f.Name
  f.Delete True
  If Err Then
    WScript.Echo "Error deleting:" & name & " - " & Err.Description
  Else
    WScript.Echo "Deleted:" & name
  End If
  On Error GoTo 0
Next
'delete all subfolders and files
For Each f In folder.SubFolders
  On Error Resume Next
  name = f.Name
  f.Delete True
  If Err Then
    WScript.Echo "Error deleting:" & name & " - " & Err.Description
  Else
    WScript.Echo "Deleted:" & name
  End If
  On Error GoTo 0
Next

0 个答案:

没有答案