1

I want to check for .raw files in my current running thumb drive and list it. And if there is more than one, then it will prompt the user to select which .raw files to use.

For example: In my current thumbdrive path (i.e. E:), I have a few .raw files.

Hello1.raw Hello2.raw Hello3.raw

So if there is only 1 .raw file, it will auto insert the .raw file path (i.e. E:\Hello.raw) to a command (vol231.exe -f E:\hello.raw imageinfo > hellllo.txt)

But if there is more than 1 .raw files, it will prompt the user to select the .raw file to insert into the command.

For example: "You have more than 1 .raw files. Please select 1." Then it will list the .raw files.

1. Hello1.raw

2. Hello2.raw

3. Hello3.raw

Then the user will select 1, 2 or 3. Then if the user select option 3. It will insert the command into vol231.exe -f E:\Hello3.raw imageinfo > end.txt.

Can anyone help me with it?

Edit:

I have this coding which somehow helps but I do not know how to fully utilize it into my needs.

FOR /F "tokens=* delims=|" %%i IN ('dir /b *.raw*') do echo %%i

1 Answer 1

1
@ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION 
:: remove variables starting $
FOR  /F "delims==" %%a In ('set $ 2^>Nul') DO SET "%%a="
SET "sourcedir=U:\sourcedir"
SET "choicebet= 0123456789abcdefghijklmnopqrstuvwxyz"
FOR /f "tokens=1*delims=[]" %%a IN (
  'dir /b /a-d "%sourcedir%\myfile*.raw" ^|find /n /v ""'
  ) DO (
 SET $!choicebet:~%%a,1!=%%b
 SET /a choices=%%a+1
)
)
CALL SET choices=%%choicebet:~0,!choices!%%
IF DEFINED $1 (
 cls
 FOR /f "tokens=1*delims==" %%a IN ('set $') DO SET "choicemade=%%a : %%b"&ECHO(!choicemade:~1!
 choice /c %choices:~1% /M "You have MORE than 1 raw files. Please select one."
 REM SET /a choicemade=!errorlevel!-1
 CALL SET choicemade=$%%choicebet:~!errorlevel!,1%%
) ELSE (
 SET choicemade=$0
)
FOR /f "tokens=1*delims==" %%a IN ('set %choicemade%') DO SET choicemade=%%b
ECHO(vol321.exe -f %sourcedir%\%choicemade% imageinfo

GOTO :EOF

I've just echoed the command that would be executed, without the output to end.txt for ease of verification.

You would need to set sourcedir appropriately for your system. The value I've used suits mine.

Sign up to request clarification or add additional context in comments.

1 Comment

I might need some time to understand your coding as I am new to batch scripting. Btw, thanks for coming forward to provide me with your help. I would like to consult you if I don't understand certain parts. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.