-1

I need a batch file (.bat) that list all txt files from a directory and list them as variables and in a new menu so I can run them.

Folder contains:

test1.php, test1.txt test2.txt, image.bmp

Then the result in the menu should be:

Press 1 for test1
Press 2 for test2

It should also look in subfolders.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Mulle1976
  • 3
  • 2
  • 3
    puh - DOS is ooold. There are no commands to do that. Well, if you were on Windows `cmd`, then it would be easy... – Stephan Apr 25 '17 at 14:46

1 Answers1

4

Assuming, you are on Windows (as DOS is "out of office" since decades...):

@echo off
setlocal enabledelayedexpansion

set n=0
for /r %%a in (*.txt) do (
  set /a n+=1
  set "menu_!n!=%%a"
  echo press !n! for %%~nxa
)
set /p "take=your choice:"
!menu_%take%! 

For help, see for /? and set /?

Note that this won't work on DOS. Even if all the commands actually exist in DOS, their capability is not the same (and of course there is no delayed expansion in DOS).

Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91