批处理文件:列出所有文件夹与数/计数器的当前目录 [英] Batch file: List all folders in current directory with number/counter
本文介绍了批处理文件:列出所有文件夹与数/计数器的当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起坏的描述,我期待下面的输出:
Sorry for bad description, i am expecting the following output:
- FolderA
- FolderB中
- FolderC
以下code不为我工作
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
计数器保持为0。
The counter stays at 0.
推荐答案
您需要的是延迟的变量扩充。对于这一点,只需做如下变化2:
What you need is delayed variable expansion. For that, simply make the following 2 changes:
-
SETLOCAL EnableDelayedExpansion
添加到您的命令文件的顶部。 - 替换
%计%
与!算!
。
- Add
setlocal EnableDelayedExpansion
to the top of your command file. - Replace
%count%
with!count!
.
的结果是:
@echo off
setlocal EnableDelayedExpansion
set /a count=0
for /d %%d in (*) do (
set /a count+=1
@echo !count!. %%d
)
pause
这篇关于批处理文件:列出所有文件夹与数/计数器的当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文