如何删除所有文件和目录(例外) [英] How to delete all files and directories with an exception

查看:91
本文介绍了如何删除所有文件和目录(例外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文件和目录,(所有目录都包含文件):

I have a few files and directories, (all directories contain files):

C:\ABC
│   file1.txt
│
├───folder1
│       oneormorefiles.ext
│
├───folder2
│       somemorefiles.ext
│
└───logs
        aaa-test-01.log
        b-test-a-02.log
        cc-test-03.log

我想删除所有目录及其包含的文件,但希望保留C:\abc\logs及其所有文件.

I want to delete all of the directories and the files they contain, but wish to keep C:\abc\logs and all of its files.

我尝试过:

PUSHD "c:\logs" && rd /s/q "c:\abc" 2>nul

,但这也会删除C:\abc\logs中的文件,(我想避免这种情况).

but this is deleting files in C:\abc\logs as well, (I want to avoid that).

谢谢

推荐答案

我建议将其作为使用FOR循环和/或DELRD的混合物的可能替代方法:

I would suggest this as a possibile alternative to using FOR loop and/or a mixture of DEL and RD:

MD "%TEMP%\$_.dummy"&&ROBOCOPY "%TEMP%\$_.dummy" "C:\abc" /E /XD logs /PURGE>NUL 2>&1&RD "%TEMP%\$_.dummy"

这篇关于如何删除所有文件和目录(例外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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