执行德尔批处理文件时,排除里面的临时文件夹 [英] Exclude a folder inside temp when executing a del batch file

查看:106
本文介绍了执行德尔批处理文件时,排除里面的临时文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么添加到我的DEL批处理文件,如果我想要一个文件夹排除我想删除一个文件夹内?

What do I add to my DEL batch file if I want to exclude a folder inside a folder I want to delete?

我有这样的code删除我所有的临时文件夹中的内容

I have this code to delete my all the contents of the temp folder

DEL /F /Q C:\temp

现在,我要排除一个名为 imptfolder 文件夹内。它是否存在与否的临时文件夹内这不应该被删除。我该怎么做呢?

Now, I want to exclude a folder named imptfolder inside. This shouldn't be deleted whether it exists or not inside the temp folder. How do I do this?

推荐答案

下面是一些批处理脚本code,它会做什么你问。

Here's some batch script code that'll do what you're asking.

for /d %%I in (c:\temp\*) do (
    if /i not "%%~nxI" equ "imptfolder" rmdir /q /s "%%~I"
)
del /q c:\temp\*

如果你只是从控制台输入以下命令,使用单一的百分比,而不是双。

If you're just entering these commands from the console, use single percents rather than double.

cd /d c:\temp
for /d %I in (*) do @(if /i not "%~I" equ "imptfolder" rmdir /q /s "%~I")
del /q *

这篇关于执行德尔批处理文件时,排除里面的临时文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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