windows 在批处理文件中删除目录树的最快方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/905500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:32:28  来源:igfitidea点击:

Fastest way to delete a tree of directories in batch file

windowsbatch-filefile-io

提问by Assaf Lavie

I need to write a batch file that received a directory that contains a huge number of empty sub-directories and deletes them all.

我需要编写一个批处理文件,该文件接收一个包含大量空子目录的目录并将它们全部删除。

What's the fastest way of doing this? (by fast I mean not like what Windows Explorer does when you try to delete such a directory...)

这样做的最快方法是什么?(快速我的意思是不像 Windows 资源管理器在您尝试删除这样的目录时所做的那样......)

Clarification:

澄清:

I'm not trying to delete onlyempty directories. It just so happens that this dir I'm trying to delete is mostly empty sub-dirs.

我不是想删除空目录。碰巧的是,我要删除的这个目录大多是空的子目录。

回答by kenj0418

rd yourdirname /s/q

Will do the job regardless of whether they are empty or not.

无论它们是否为空,都将完成工作。

回答by Nathan Fellman

I'm not sure if I understood the question. If you just want to delete the tree then you can just use rd /s. However, if you only want to delete emptydirectories, then you can do the following using Cygwin.

我不确定我是否理解这个问题。如果您只想删除树,那么您可以使用rd /s. 但是,如果您只想删除目录,则可以使用 Cygwin 执行以下操作。

find -type d -empty | xargs rmdir

The standard IT build where I work has Cygwin installed, and I've used this more than once.

我工作的标准 IT 版本安装了 Cygwin,我已经不止一次使用过它。