Board logo

標題: [發問] 如何用CMD刪除資料夾呢 [打印本頁]

作者: v60i    時間: 2011-10-27 09:16     標題: 如何用CMD刪除資料夾呢

請問大大
如果我有一大堆資料夾
AAAAA
AAA01
AAASFGV
ADCVVB
VGBVB
DGGBDF
類似這些亂數的檔名資料夾
我只要刪除開頭AA資料夾全部就可以
該怎麼寫呢?
作者: downling    時間: 2011-10-27 16:25

  1. del AA*.*
  2. rd AA*.
複製代碼
windows XP/7可用
作者: v60i    時間: 2011-10-28 06:51

回復 2# downling

大大不行哦
你的方法不能用
作者: downling    時間: 2011-10-28 08:40

那個地方不行?
出現什麼資訊?
作者: v60i    時間: 2011-10-28 20:46

回復 4# downling


    大大 你自己有先行試看看嗎?

他說 檔案名稱、目錄名稱或磁碟區標籤語法錯誤。
作者: downling    時間: 2011-11-1 13:04

回復 5# v60i

忘了rd不吃萬用字元
你可以去抓98的deltree.exe來用
或是網路上有人貼出來的一篇
你可以自己試一下
  1. Option Explicit

  2. Dim objFSO, objTempFolder, strTempFolder

  3. Const TEMP_FOLDER = 2

  4. Set objFSO        = CreateObject( "Scripting.FileSystemObject" )
  5. Set objTempFolder = objFSO.GetSpecialFolder( TEMP_FOLDER )
  6. strTempFolder     = objTempFolder.Path

  7. DelTree strTempFolder, True


  8. Sub DelTree( myFolder, blnKeepRoot )
  9. ' With this subroutine you can delete folders and their content,
  10. ' including subfolders.
  11. '
  12. ' You can specify if you only want to empty the folder, and thus
  13. ' keep the folder itself, or to delete the folder itself as well.
  14. ' Root directories and some (not all) vital system folders are
  15. ' protected: if you try to delete them you'll get a message that
  16. ' deleting these folders is not allowed.
  17. '
  18. ' Use: Deltree.vbs <Path to delete>, True (false)
  19. '
  20. ' Arguments:
  21. ' myFolder     [string]   the folder to be emptied or deleted
  22. ' blnKeepRoot  [boolean]  if True, the folder is emptied only,
  23. '                         otherwise it will be deleted itself too
  24. '
  25. '
  26.     Dim arrSpecialFolders(3)
  27.     Dim objMyFSO, objMyFile, objMyFolder, objMyShell
  28.     Dim objPrgFolder, objPrgFolderItem, objSubFolder, wshMyShell
  29.     Dim strPath, strSpecialFolder

  30.     Const WINDOWS_FOLDER =  0
  31.     Const SYSTEM_FOLDER  =  1
  32.     Const PROGRAM_FILES  = 38

  33.     ' Use custom error handling
  34.     On Error Resume Next

  35.     ' List the paths of system folders that should NOT be deleted
  36.     Set wshMyShell       = CreateObject( "WScript.Shell" )
  37.     Set objMyFSO         = CreateObject( "Scripting.FileSystemObject" )
  38.     Set objMyShell       = CreateObject( "Shell.Application" )
  39.     Set objPrgFolder     = objMyShell.Namespace( PROGRAM_FILES )
  40.     Set objPrgFolderItem = objPrgFolder.Self

  41.     arrSpecialFolders(0) = wshMyShell.SpecialFolders( "MyDocuments" )
  42.     arrSpecialFolders(1) = objPrgFolderItem.Path
  43.     arrSpecialFolders(2) = objMyFSO.GetSpecialFolder( SYSTEM_FOLDER  ).Path
  44.     arrSpecialFolders(3) = objMyFSO.GetSpecialFolder( WINDOWS_FOLDER ).Path

  45.     Set objPrgFolderItem = Nothing
  46.     Set objPrgFolder     = Nothing
  47.     Set objMyShell       = Nothing
  48.     Set wshMyShell       = Nothing

  49.     ' Check if a valid folder was specified
  50.     If Not objMyFSO.FolderExists( myFolder ) Then
  51.         WScript.Echo "Error: path not found (" & myFolder & ")"
  52.         WScript.Quit 1
  53.     End If
  54.     Set objMyFolder = objMyFSO.GetFolder( myFolder )

  55.     ' Protect vital system folders and root directories from being deleted
  56.     For Each strSpecialFolder In arrSpecialFolders
  57.         If UCase( strSpecialFolder ) = UCase( objMyFolder.Path ) Then
  58.             WScript.Echo "Error: deleting """ _
  59.                        & objMyFolder.Path & """ is not allowed"
  60.             WScript.Quit 1
  61.         End If
  62.     Next

  63.     ' Protect root directories from being deleted
  64.     If Len( objMyFolder.Path ) < 4 Then
  65.         WScript.Echo "Error: deleting root directories is not allowed"
  66.         WScript.Quit 1
  67.     End If

  68.     ' First delete the files in the directory specified
  69.     For Each objMyFile In objMyFolder.Files
  70.         strPath = objMyFile.Path
  71.         objMyFSO.DeleteFile strPath, True

  72.     Next

  73.     ' Next recurse through the subfolders
  74.     For Each objSubFolder In objMyFolder.SubFolders
  75.         DelTree objSubFolder, False
  76.     Next

  77.     ' Finally, remove the "root" directory unless it should be preserved
  78.     If Not blnKeepRoot Then
  79.         strPath = objMyFolder.Path
  80.         objMyFSO.DeleteFolder strPath, True

  81.     End If

  82.     ' Clean-up after thyself
  83.     On Error Goto 0
  84.     Set objMyFolder = Nothing
  85.     Set objMyFSO    = Nothing
  86. End Sub
複製代碼

作者: v60i    時間: 2011-11-3 03:51

回復 6# downling


   大大
請問這是vb還是cmd??
作者: downling    時間: 2011-11-3 09:13

引用原文
If you wanted to delete the contents of the directory c:\Temp, but not remove the TEMP directory, usage would be:

DELTREE.vbs c:\Temp, TRUE

If you wish to delete the contents of c:\Temp, AND the directory c:\temp...

DELTREE.vbs c:\Temp, FALSE


代碼就是上面po的

Note: Just copy the code above, paste it into notepad, and save it as DELTREE.vbs (or whatever you wish to name it). Run it from a command prompt. You may have to use a fully qualified path depending on where you save it.

作者: v60i    時間: 2011-11-3 20:57

回復 8# downling


    s@@ 看來真的只能用vb囉
作者: groover    時間: 2011-12-18 13:33

需要用 vb 嗎?? 直接在 cmd 下用 dir >1.txt 將所有檔案寫成 1.txt 後, 再進 Excel 中把不要的檔, 前面加一欄, 那欄中加上 del, 再將 Excel 的檔copy 或 寫成文字檔, 變成 .bat 檔即可, 不到 10 分鐘搞定.
作者: v60i    時間: 2011-12-21 07:14

本帖最後由 v60i 於 2011-12-21 07:16 編輯

回復 10# groover

照大大的方法,我直接按鍵盤的DEL 可能會更快
    大大,可能你還看不太懂我的問題哦
請加油!
作者: 456hj    時間: 2012-2-13 13:11

感覺好難
CC不知道能不能用
作者: asd16801680    時間: 2016-3-18 23:02

很多朋友對於電腦內的 thumbs.db 的隱藏文件,非常頭痛,到底是不是病毒呢?

從Windows98開始,系統增加了圖片預視功能,保存了圖片的檔夾下會產生一個名為“Thumbs.db”的檔,這個檔會隨著圖片檔的增加而膨脹。所以可以使用下列方式批量刪除該檔 :



點擊 開始 → 運行,輸入:cmd 按 enter。然後在“命令提示符”視窗下輸入:



del X:Thumbs.db /f /s /q /a (X代表你要操作的盤符,如果是C盤就把X改成C)



強制刪除X盤下所有目錄內(包括X盤本身)的Thumb.db檔並且不提示是否刪除



參數含義:



/f 強制刪除唯讀檔案。



/q 指定靜音狀態。不提示您確認刪除。



/s 從當前目錄及其所有子目錄中刪除指定檔。顯示正在被刪除的檔案名。



/a 按照屬性來刪除。



比如要清除C盤:




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)