gpt4 book ai didi

windows - 在批处理文件中,如何删除所有非特定类型的文件

转载 作者:可可西里 更新时间:2023-11-01 11:15:13 25 4
gpt4 key购买 nike

我正在编写一个批处理文件,需要删除某个目录中的所有文件及其所有子目录除了特定类型的文件。

我该怎么做?

最佳答案

在一位同事寻求帮助删除文件夹和所有子文件夹中除某些类型的文件外的所有文件,同时保持目录结构后,我写了这个批处理文件。我建议在尝试此操作之前备份您的文件夹。只需打开记事本并粘贴以下内容,将其另存为 .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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com