0

I got a problem, Im trying to make a numerated list of a directory and its containing folders for a text based menu. Main Problem is, that i want them to be numerated. for example:
1:Folder A
2:Folder B
3:Folder C
my idea was to write the directory and its containing folders in a seperate file and read the lines after each other adding a variable in front which increases each line. sadly it does not work. All i get is:
0:Folder A
0:Folder B
0:Folder C

    @echo off
dir "directory" /a:d /b > tmp.txt
for /f "tokens=* delims= " %%a in (tmp.txt) do (
    set /a N+=1
    echo %N%:%%a
)

regards

Alex
  • 112
  • 10

1 Answers1

0

Ok I actually got the soloution with the help of this link Example of delayed expansion in batch file

@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
set COUNT=0
dir "directory" /a:d /b > tmp.txt  
  for /f "tokens=* delims= " %%a in (tmp.txt) do (
    set /A COUNT=!COUNT! + 1
    ECHO !COUNT!:%%a
  )
Community
  • 1
  • 1
Alex
  • 112
  • 10