- 帖子
- 16
- 主題
- 1
- 精華
- 0
- 積分
- 60
- 點名
- 0
- 作業系統
- Windows 7 Professional
- 軟體版本
- Office 2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2011-8-29
- 最後登錄
- 2014-2-27
|
6#
發表於 2011-11-1 13:04
| 只看該作者
回復 5# v60i
忘了rd不吃萬用字元
你可以去抓98的deltree.exe來用
或是網路上有人貼出來的一篇
你可以自己試一下- Option Explicit
- Dim objFSO, objTempFolder, strTempFolder
- Const TEMP_FOLDER = 2
- Set objFSO = CreateObject( "Scripting.FileSystemObject" )
- Set objTempFolder = objFSO.GetSpecialFolder( TEMP_FOLDER )
- strTempFolder = objTempFolder.Path
- DelTree strTempFolder, True
- Sub DelTree( myFolder, blnKeepRoot )
- ' With this subroutine you can delete folders and their content,
- ' including subfolders.
- '
- ' You can specify if you only want to empty the folder, and thus
- ' keep the folder itself, or to delete the folder itself as well.
- ' Root directories and some (not all) vital system folders are
- ' protected: if you try to delete them you'll get a message that
- ' deleting these folders is not allowed.
- '
- ' Use: Deltree.vbs <Path to delete>, True (false)
- '
- ' Arguments:
- ' myFolder [string] the folder to be emptied or deleted
- ' blnKeepRoot [boolean] if True, the folder is emptied only,
- ' otherwise it will be deleted itself too
- '
- '
- Dim arrSpecialFolders(3)
- Dim objMyFSO, objMyFile, objMyFolder, objMyShell
- Dim objPrgFolder, objPrgFolderItem, objSubFolder, wshMyShell
- Dim strPath, strSpecialFolder
- Const WINDOWS_FOLDER = 0
- Const SYSTEM_FOLDER = 1
- Const PROGRAM_FILES = 38
- ' Use custom error handling
- On Error Resume Next
- ' List the paths of system folders that should NOT be deleted
- Set wshMyShell = CreateObject( "WScript.Shell" )
- Set objMyFSO = CreateObject( "Scripting.FileSystemObject" )
- Set objMyShell = CreateObject( "Shell.Application" )
- Set objPrgFolder = objMyShell.Namespace( PROGRAM_FILES )
- Set objPrgFolderItem = objPrgFolder.Self
- arrSpecialFolders(0) = wshMyShell.SpecialFolders( "MyDocuments" )
- arrSpecialFolders(1) = objPrgFolderItem.Path
- arrSpecialFolders(2) = objMyFSO.GetSpecialFolder( SYSTEM_FOLDER ).Path
- arrSpecialFolders(3) = objMyFSO.GetSpecialFolder( WINDOWS_FOLDER ).Path
- Set objPrgFolderItem = Nothing
- Set objPrgFolder = Nothing
- Set objMyShell = Nothing
- Set wshMyShell = Nothing
- ' Check if a valid folder was specified
- If Not objMyFSO.FolderExists( myFolder ) Then
- WScript.Echo "Error: path not found (" & myFolder & ")"
- WScript.Quit 1
- End If
- Set objMyFolder = objMyFSO.GetFolder( myFolder )
- ' Protect vital system folders and root directories from being deleted
- For Each strSpecialFolder In arrSpecialFolders
- If UCase( strSpecialFolder ) = UCase( objMyFolder.Path ) Then
- WScript.Echo "Error: deleting """ _
- & objMyFolder.Path & """ is not allowed"
- WScript.Quit 1
- End If
- Next
- ' Protect root directories from being deleted
- If Len( objMyFolder.Path ) < 4 Then
- WScript.Echo "Error: deleting root directories is not allowed"
- WScript.Quit 1
- End If
- ' First delete the files in the directory specified
- For Each objMyFile In objMyFolder.Files
- strPath = objMyFile.Path
- objMyFSO.DeleteFile strPath, True
- Next
- ' Next recurse through the subfolders
- For Each objSubFolder In objMyFolder.SubFolders
- DelTree objSubFolder, False
- Next
- ' Finally, remove the "root" directory unless it should be preserved
- If Not blnKeepRoot Then
- strPath = objMyFolder.Path
- objMyFSO.DeleteFolder strPath, True
- End If
- ' Clean-up after thyself
- On Error Goto 0
- Set objMyFolder = Nothing
- Set objMyFSO = Nothing
- End Sub
複製代碼 |
|