获取子目录的名称(Windows CMD)

时间:2016-07-18 15:18:53

标签: batch-file cmd

如何列出文件夹中的子目录并将其名称存储在临时变量中?

1 个答案:

答案 0 :(得分:4)

用于1级目录:

@echo off
setlocal enableDelayedExpansion
set "direcotries="
for /d %%a in (*) do (
  set "direcotries=!direcotries!;%%a"
)
echo %direcotries%

用于递归搜索:

@echo off
setlocal enableDelayedExpansion
set "direcotries="
for /r /d %%a in (*) do (
  set "direcotries=!direcotries!;%%a"
)
echo %direcotries%