Batch file: List all folders in current directory

2019-07-19 03:36发布

Sorry for bad description, i am expecting the following output:

  1. FolderA
  2. FolderB
  3. FolderC

The following code does not work for me

@ECHO OFF
set /a count=0

for /d %%d in (*) do (
set  /a count+=1
@echo %count%. %%d 
)
PAUSE

The counter stays at 0.

1条回答
家丑人穷心不美
2楼-- · 2019-07-19 04:13

What you need is delayed variable expansion. For that, simply make the following 2 changes:

  1. Add setlocal EnableDelayedExpansion to the top of your command file.
  2. Replace %count% with !count!.

The result is:

@echo off
setlocal EnableDelayedExpansion
set /a count=0

for /d %%d in (*) do (
    set /a count+=1
    @echo !count!. %%d 
)
pause
查看更多
登录 后发表回答