Hi All !!
I have looked every where and tried a thousand things but I can not get this to work ... What I want to do is run a DIR /b cammand and display the subdirectories found on the screen with a number (subscript) for future reference / selection - the output should be similar to the following ...
1 firstSubdir
2 scndSubdir
3 anotherSubdir
4 lastSubdir
I have tried using the for loop to display the number and the subdir name but i cannot increment the number - my code
set /a cnt=0
for /f "tokens=*" %%g in ('dir /b') do (
echo '%%g'
set /A cnt=%cnt% + 1
echo cnt=%cnt% )
The output ends up showing the directory name but always 0 for the number
- What am I doing wrong ????
Dir /b output into an Array
Moderator: DosItHelp
Re: Dir /b output into an Array
Code: Select all
@echo off
setlocal enabledelayedexpansion
set /a cnt=0
for /f "tokens=*" %%g in ('dir /b') do (
set /A cnt+=1
echo !cnt! '%%g'
)
endlocal
Re: Dir /b output into an Array
In the MSdos days to create a simple menu, the screen was generated like this:
Code: Select all
dir /ad /b |find /n /v ""
Re: Dir /b output into an Array
foxidrive wrote:In the MSdos days to create a simple menu, the screen was generated like this:Code: Select all
dir /ad /b |find /n /v ""
Totally forgot about the FIND usage. Thanks foxidrive.
Re: Dir /b output into an Array
Awesome !!!
Thank you Squashman & Foxidrive
Thank you Squashman & Foxidrive