如何在 Windows XP 中递归删除特定目录中的文件

如何在 Windows XP 中递归删除特定目录中的文件

我有很多目录。假设目录 1、目录 2、目录 3每个目录都有一个名为的子目录临时目录

我想删除临时目录从 dir1 到 dir3,而无需手动进入每个目录。临时目录本身删除与不删除并不是问题。

答案1

尝试del /S directory

cd 进入上面的目录,然后执行。

答案2

前往搜索并搜索临时目录在要扫描的目录上。获取所有结果并按删除。

太简单了 :)

答案3

这可能并不适合所有人,但我喜欢它,首先要了解一些事情。1
) 我喜欢并使用命令行,因为创建批处理文件来执行冗余任务对我来说是更好的选择。2
) 我总是使用移植到 Windows 的标准 gnu linux 命令来扩展我的命令行功能。它们可以在以下位置找到:http://sourceforge.net/projects/unxutils/。我只是从 ZIP 文件中取出我感兴趣的 exe 文件(它们位于 ZIP 的 /usr/local/wbin 目录中)并将它们放在我路径中的某个目录中。因为我经常使用它们,所以我实际上将它们全部放在 /unix 目录中,并将其放在路径的开头。3
) 对于此任务,特别需要的实用程序是 find 和 rm。如果 find 命令和 Windows find 发生冲突,只需在命令中使用整个路径。

为了专注于删除 tempdir 目录,假设 dir1 dir2 dir3 内可能还有其他文件或目录,我会执行以下操作。

进入 dir1 dir2 dir3 的父目录并运行

find . -name tempdir -type d -depth -ok rm -rf {} ;

意思是

find .          - Start in this directory and find something for me.
-name temdir    - The name of what we are looking for.
-type d         - Look for directories (named as above).
-depth          - Look down the tree first so if you remove something it won't complain.
-ok rm -rf {} ; - The real power ok just means to ask before doing anything, 

如果 ok 被替换为 exec,那么它就会执行此操作。因此,对所有匹配的“找到的条目”执行以下操作 rm -rf,或者换句话说,递归删除强制删除所有名为 temdir 的目录

相关内容