0

如何递归遍历 Windows 批处理文件中的目录结构?

我在 Internet 上没有找到任何示例,除了作者在文本文件中列出所有目录然后读取文本文件并进入目录并重复的示例。

4

1 回答 1

1

检查FOR /R循环。

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Walks the directory tree rooted at [drive:]path, executing the FOR
statement in each directory of the tree.  If no directory
specification is specified after /R then the current directory is
assumed.  If set is just a single period (.) character then it
will just enumerate the directory tree.

一个例子:

C:\>md dummy
C:\>cd dummy
C:\dummy>md foo
C:\dummy>md foo\bar
C:\dummy>for /r %i in (.);do @echo %i

给出输出:

C:\dummy\.
C:\dummy\foo\.
C:\dummy\foo\bar\.
于 2013-11-07T11:58:42.647 回答