Dir /b output into an Array
Posted: 06 Mar 2012 11:27
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 ????
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 ????