我正在查找一個DOS腳本來刪除根目錄中除根目錄中的一組批處理文件(* .bat)以外的所有文件和子目錄。任何DOS的運動員都知道一個簡單的方法來做到這一點?如何刪除除DOS中某些文件以外的所有文件/子目錄?
更新
感謝您的幫助大家。這就是我現在的位置(見下文)。我正在使用Ken的建議刪除這些文件。我想知道如果由於鎖定文件/目錄導致del
或RD
命令失敗,我該如何停止運行此腳本。任何人都知道嗎?現在,這個腳本會在刪除後執行一些操作,如果任何刪除操作失敗,我想停止腳本。
@echo off
REM *********************************************************************
REM * Delete all files and subdirs except for batch files in the root *
REM *********************************************************************
REM Delete all files in current dir except bat files. Does this by a) setting the attributes of *.bat files to
REM readonly and hidden, b) deleting the rest, c) reseting the attributes
attrib +r +s *.bat
del *.* /S /Q
attrib -r -s *.bat
REM Deletes ALL subdirectories
FOR /D %%G in (*) DO RD /s /q %%G
這是否意味着:不要刪除根目錄中的任何.bat文件?或者不要刪除這些.bat,如果它們在根目錄中? – colithium 2009-02-17 20:51:49
不要刪除根目錄中的_any_ .bat文件 – 2009-02-17 20:54:11