The following batch of script should do what you want, explanation below:
@ECHO OFF SET index=1 SETLOCAL ENABLEDELAYEDEXPANSION FOR %%f IN (*.*) DO ( SET file!index!=%%f ECHO !index! - %%f SET /A index=!index!+1 ) SETLOCAL DISABLEDELAYEDEXPANSION SET /P selection="select file by number:" SET file%selection% >nul 2>&1 IF ERRORLEVEL 1 ( ECHO invalid number selected EXIT /B 1 ) CALL :RESOLVE %%file%selection%%% ECHO selected file name: %file_name% GOTO :EOF :RESOLVE SET file_name=%1 GOTO :EOF
First of all, this script uses something like an array to store file names. This array is populated in FOR -loop. The loop body is executed once for each file name found in the current directory.
An array actually consists of a set of variables, starting with file and with an added number (for example, file1 , file2 ). The number is stored in the variable index and increases in each iteration of the loop. In the loop body, this number and the corresponding file name are also printed
In the next part, the SET /P command asks the user to enter a number, which is then stored in the selection variable. The second SET command and the next IF are used to check whether the entered number will give a valid array index by checking for the fileX variable.
Finally, the RESOLVE subroutine is used to copy the contents of the variable formed by file +, the number entered in selection into a variable called file_name , which can then be used for further processing.
Hope that gives some clues.
source share