我正在编写一个批处理文件,需要删除某个目录中的所有文件及其所有子目录除了特定类型的文件。
我该怎么做?
最佳答案
在一位同事寻求帮助删除文件夹和所有子文件夹中除某些类型的文件外的所有文件,同时保持目录结构后,我写了这个批处理文件。我建议在尝试此操作之前备份您的文件夹。只需打开记事本并粘贴以下内容,将其另存为 .bat 而不是 .txt 祝你好运! ~卡罗琳
REM Use at your own risk, it does a mass DELETE of everything!
SET /p ExcludeFiles=What file type should be kept (NOT deleted)? Type the file name(s) inside parantheses. example: (pdf) or (shp dbf shx)
SET /p MapDrive=What drive letter is the folder in? example: c or n
SET /p Directory=Drag the folder you would like to modify into this command prompt then press ENTER.
%MapDrive%:
cd %Directory%
attrib +a *.* /s
echo %date%
for %%i in %ExcludeFiles% do attrib -a *.%%i /s
echo %date%
del %Directory%\*.* /s /a:a /q
echo %date%
attrib +a %Directory%\*.* /s
echo %date%
关于windows - 在批处理文件中,如何删除所有非特定类型的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/863552/