删除所有子目录和子文件而不删除父/根目录? [英] Remove All Sub-Directories and Sub-Files Without Removing Parent/Root Directory?

查看:1161
本文介绍了删除所有子目录和子文件而不删除父/根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Windows批处理,命令是删除文件夹的所有子目录和子文件夹,而不删除/删除所述父/根文件夹?

Via Windows Batch, what would the command be to remove all sub directories and sub files of a folder without deleting/removing the said parent/root folder?

我到目前为止所尝试的:

Here's what I have tried so far:

ECHO "Good riddance, cache! Muahahahahahaha"
cd "C:\Users\abrewer\Desktop\cache"
del * /q

仅删除文件,而不删除子文件夹。我也试过RMDIR和RD,这两个命令似乎删除父/根目录。

The above only removes files, but not sub folders. I have also tried RMDIR and RD, those two commands seem to remove the parent/root directory.

推荐答案

it:

cd "C:\Users\abrewer\Desktop\cache"
rd /s /q .

它尝试删除父目录时会输出错误消息,

It outputs an error message when it tries and fails to delete the parent directory, but otherwise it works perfectly.

或者,如下:

cd "C:\Users\abrewer\Desktop\cache"
del * /q
for /D %%i in (*) do rd /s /q "%%i"

可能会正常工作。如果您从命令行而不是批处理文件运行,请记住只使用单百分号。

might work. Remember to only use single percent signs if you're running from the command line rather than in a batch file.

这篇关于删除所有子目录和子文件而不删除父/根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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