【发布时间】:2010-10-08 04:51:53
【问题描述】:
我正在寻找一个 DOS 脚本来删除根目录中的所有文件和子目录,但根目录中的一组批处理文件 (*.bat) 除外。那里有知道简单方法的 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?
-
不要删除根目录下的任何个.bat文件
标签: dos