Windows批处理脚本文件夹中删除一切除一 [英] Windows batch script to delete everything in a folder except one

查看:115
本文介绍了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:\myfolder\keepit
FOR /D %%i IN ("D:\myfolder\*") DO RD /S /Q "%%i" DEL /Q "D:\myfolder\*.*"
ATTRIB -H D:\myfolder\keepit

这篇关于Windows批处理脚本文件夹中删除一切除一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆