Windows批处理脚本删除文件夹中除一个之外的所有内容 [英] Windows batch script to delete everything in a folder except one
本文介绍了Windows批处理脚本删除文件夹中除一个之外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本来删除文件夹中的所有子文件夹和文件:
I have a script to delete all subfolders and files in a folder:
FOR /D %%i IN ("D:myfolder*") DO RD /S /Q "%%i" & DEL /Q "D:myfolder*.*"
而且效果很好!唯一的问题是我想排除一个或多个文件夹,例如 XCOPY 排除功能.
And it works great! Only problem is that I would like to exclude one or more folders, like the XCOPY exclude feature.
我只是不知道如何将其添加到脚本中.
I just cant figure how I could add that to the script.
推荐答案
您可以尝试在 for 循环之前隐藏文件夹,然后再取消隐藏,如下所示:
You could try to hide the folders before the for-loop, and unhide them afterwards, like this:
ATTRIB +H D:myfolderkeepit
FOR /D %%i IN ("D:myfolder*") DO RD /S /Q "%%i" DEL /Q "D:myfolder*.*"
ATTRIB -H D:myfolderkeepit
这篇关于Windows批处理脚本删除文件夹中除一个之外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文