4

I am looking how to get list of all directories to be used in FOR loop.

So far I have work around:

set folderList = (folder1 folder2 folder3 folder4)
FOR %%i in %folderList% do zip %%i D:\...my_path...\%%i\*.*

is it possible that folderList would be generated dynamically ?

4

3 回答 3

6

假设您要列出 c:\temp 的子目录

for /f %%i in ('dir c:\temp /ad /b') do echo %%i

这将列出 c:\temp 的文件夹名称,如果要递归获取它,只需将 /s 添加到 dir 命令:

for /f %%i in ('dir c:\temp /ad /b /s') do echo %%i

至于@dbenham 评论(谢谢)要正确处理带空格的目录,只需将 tokens=* 添加到 for :

 for /f "tokens=*" %%i in ('dir c:\temp /ad /b') do echo %%i
于 2013-02-08T08:57:06.883 回答
2

请尝试以下代码:

for /d %%F in ("d:\...my_path...\*") do zip "%%~nxF" "%%F\*.*"
于 2013-02-08T12:11:13.260 回答
0

我不确定有什么不同,但上面列出的双 %% 都无法正常工作。

但是,这对我有用:

for /f "tokens=*" %i in ('dir c:\temp /ad /b') do echo %I
于 2014-06-25T22:08:16.163 回答