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

查看:1245
本文介绍了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循环之前隐藏文件夹, p>

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天全站免登陆