I have the following script but I want to map the numbers to the variable but do not know how to. So if a user enters 0, I want it to search for the event name NewUser.
#echo off
mode con:cols=40 lines=40
set /p customerID="Enter Customer ID: "
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PLEASE SELECT THE EVENT FROM THE MENU BELOW
ECHO ...............................................
ECHO.
ECHO Event Code Event Name
ECHO.
ECHO 0 NewUser
ECHO 1 ExistingUser
ECHO 2 EmailAdded
ECHO 3 AccountProblem
ECHO 4 Lost
ECHO.
SET /P event=Type the event code and then press ENTER:
IF %event%==0 set event=NewUser GOTO find
IF %M%==1 set event=ExistingUser GOTO find
IF %M%==2 set event=EmailAdded GOTO find
IF %M%==3 set event=AccountProblem GOTO find
IF %M%==4 set event=Lost GOTO find
pause
:find
pause
setlocal enableextensions disabledelayedexpansion
pause
set "sourceFolder=C:\test"
set "targetFolder=C:\test2"
pause
set "customerID=%customerID%"
set "NewUser=%Event%"
pause
for /f "delims=" %%a in ('
findstr /m /s /l /c:"%customerID%" "%sourceFolder%\*"
^| findstr /f:/ /m /l /c:"%event%"
') do (
copy "%%~fa" "%targetFolder%"
)
pause
The first version of your code was closer to correct solution than current one; you need to use two nested for /F loops as follows:
for /f "delims=" %%a in ('
findstr /I /m /s /l /c:"%customerID%" "%sourceFolder%\*.txt"
') do for /f "delims=" %%A in ('
findstr /I /m /l /c:"%event%" "%%~fa"
') do (
rem 'copy' command is merely displayed using ECHO for debugging purposes
ECHO copy "%%~fa" "%targetFolder%"
)
Next commented code snippet could help to improve the script:
#ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
set "customerID="
:customerID
set /p customerID="Enter Customer ID: "
if not defined customerID goto :customerID
REM instead of above test, you could apply next statement about `set /P`:
REM If the user does not enter anything (just presses return)
REM then the variable will be unchanged and an ERRORLEVEL will be set.
rem CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PLEASE SELECT THE EVENT FROM THE MENU BELOW
ECHO ...............................................
ECHO.
ECHO Event Code Event Name
ECHO.
ECHO 0 NewUser
ECHO 1 ExistingUser
ECHO 2 EmailAdded
ECHO 3 AccountProblem
ECHO 4 Lost
ECHO.
REM SET /P M=Type the event code and then press ENTER:
choice /C 01234 /M "Type the event code"
REM 0 means that an user's reply to "Terminate batch job (Y/N)?" was not "y"
IF %ERRORLEVEL% EQU 0 echo "Ctrl-C" or "Ctrl-Break" pressed&goto :NoSearch
REM 255 means another error
IF ERRORLEVEL 255 goto :MENU
REM ERRORLEVEL number Specifies a true condition if the last program run
REM returned an exit code EQUAL TO OR GREATER THAN the number
REM specified.
IF ERRORLEVEL 1 set "event=NewUser"
IF ERRORLEVEL 2 set "event=ExistingUser"
IF ERRORLEVEL 3 set "event=EmailAdded"
IF ERRORLEVEL 4 set "event=AccountProblem"
IF ERRORLEVEL 5 set "event=Lost"
REM Note that in above code, ERRORLEVEL parameters are tested in INCREASING order
REM Used only in this special case
REM (no need of GOTO statement, 'event' variable is set correctly)
REM
REM although CHOICE /? says:
REM When you use ERRORLEVEL parameters in a batch program,
REM list them in decreasing order.
:NOTE
set "sourceFolder=D:\test"
set "targetFolder=D:\test2"
rem ??? set "customerID=%customerID%"
rem ??? set "event=%event%"
rem debugging output
echo looking for "customerID=%customerID%" "event=%event%"
for /f "delims=" %%a in ('
findstr /I /m /s /l /c:"%customerID%" "%sourceFolder%\*.txt"
') do for /f "delims=" %%A in ('
findstr /I /m /l /c:"%event%" "%%~fa"
') do (
rem 'copy' command is merely displayed using ECHO for debugging purposes
ECHO copy "%%~fa" "%targetFolder%"
)
:NoSearch
pause
Change your For loop like this and retest:
FOR /F "DELIMS=" %%A IN (
'FINDSTR/MSC:"%customerID%" "%sourceFolder%\*"^|FINDSTR/MIF:/ /C:"%event%"'
) DO COPY "%%A" "%targetFolder%"
EDIT
I have added a modified version of your script to include the new requirement of a three digit event code. Just adjust it's value in the script as necessary, (lines nineteen to twenty three).
#ECHO OFF
MODE CON:COLS=52 LINES=40
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
(SET sourceFolder=C:\test)
(SET targetFolder=C:\test2)
SET /P "customerID=Enter Customer ID: "
:MENU
CLS
ECHO=
ECHO= ..................................................
ECHO= PLEASE SELECT THE OPTION FROM THE EVENT MENU BELOW
ECHO= ..................................................
ECHO=
ECHO= Option Event Name Event Code
ECHO=
ECHO. 1. NewUser A00
ECHO. 2. ExistingUser A01
ECHO. 3. EmailAdded A02
ECHO. 4. AccountProblem A03
ECHO. 5. Lost A04
ECHO=
CHOICE /C 12345 /M "CHOOSE AN OPTION"
SET "Option=%ERRORLEVEL%"
FOR /F "TOKENS=1-4 DELIMS=. " %%A IN ('FINDSTR/BC:"ECHO. " "%~f0"'
) DO IF "%%B"=="%Option%" (SET "Name=%%C" & SET "Code=%%D")
FOR /F "DELIMS=" %%A IN (
'FINDSTR/MISC:"%customerID%" "%sourceFolder%\*"^|FINDSTR/MIF:/ /C:"%Name%"'
) DO COPY "%%A" "%targetFolder%"
PAUSE
Please make sure that %sourceFolder% is a full path and %targetFolder% already exists, (see line six).
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to make an easy messenger program for our office.
I'm not sure what I am missing, but everytime I try running the code for options, it just messages my computer and not the one I am trying to message. I am able to message the other computer if I don't have the easy options.
Please Help!
I would like to just choose a number and have the program paste that choice to the prompt. ex the user chose 1, that is person a (code for person a is /server:ECRCL). The code "/server:ECRCL" is now showing on the prompt for the "c" in the msg code. (%c% %m%)*
Here is my code:
#echo off
Title Doodle's Messenger Program
echo Messenger
chdir /
echo Select a Person
echo 1) Person a
echo 2) Person b
echo 3) Person c
echo 4) Person d
:START
echo ========================================
set /p c=Choose the number of the person you would like to message:
if %c%=="1" echo /server:ECRCL
if %c%=="2" echo /server:ECRCB
if %c%=="3" echo /server:ECRCCI
if %c%=="4" echo /server:ECRCCO
:A
set /p m=Message:
msg * %c% %m%
GoTo A
:1
: echo %/server:ECRCL /time:300 /v /w%
:2
:/server:ECRCB
:3
:/server:ECRCCI
:4
:/server:ECRCCO
The following script does work for messaging but I would like to make it easier for others with typing 1, 2, 3, or 4
#echo Copy one of the following computers you would like to message and paste it where it asks for the computer name.
#echo person a - /server:ECRCL
#echo person b - /server:ECRCB
#echo person c - /server:ECRCCI
#echo person d - /server:ECRCCO
:START
set /p c=Enter Selection:
:A
set /p m=Message:
msg * %c% %m%
GoTo A
Here's an example which may assist you.
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Title Doodle's Messenger Program
Set "msg=%SYSTEMROOT%\System32\msg.exe"
If %PROCESSOR_ARCHITECTURE:~-2% Equ 86 If Defined PROCESSOR_ARCHITEW6432 Set "msg=%SYSTEMROOT%\SysNative\msg.exe"
For %%G In ("%msg%") Do If "%%~aG" Lss "-" (Set "msg=") Else If "%%~aG" GEq "d" Set "msg="
If Not Defined msg (Echo Error! The system file msg.exe is missing.
"%__AppDir__%timeout.exe" /T 3 /NoBreak 1> NUL
GoTo :EOF)
:Start
Echo(
Echo Messenger Selection List
Echo 1. Viktor [//ECRCL]
Echo 2. Rashi [//ECRCB]
Echo 3. Kian [//ECRCCI]
Echo 4. Cedric [//ECRCCO]
Echo(
"%__AppDir__%choice.exe" /C 1234 /N /M "Enter the number for the user you would like to message."
If %ErrorLevel% Equ 1 Set "Svr=ECRCL"
If %ErrorLevel% Equ 2 Set "Svr=ECRCB"
If %ErrorLevel% Equ 3 Set "Svr=ECRCCI"
If %ErrorLevel% Equ 4 Set "Svr=ECRCCO"
:AskMessage
Set "m="
Set /P "m=Please type your message, then press the enter key>"
If Not Defined m (
Echo Empty messages are not allowed!
"%__AppDir__%timeout.exe" /T 2 /NoBreak 1> NUL
GoTo AskMessage
)
%msg% * /server:%svr% %m%
GoTo Start
As Compo has stated, the choice command is the option for this style of menu, however it's possible to use the value returned by choice in a more direct fashion to enact the desired commands by combining indexed variables with associated variables and Delayed expansion with For loop metavariables to pull the server Id from the indexed recipient number.
#Echo Off& Setlocal DisableDelayedExpansion
rem // Macro Definitions
Set "MSG=%SYSTEMROOT%\System32\msg.exe * "
Set "List/D/V=Set "#$L=0"&Set "$$L="&For %%n in (1 2)Do if %%n==2 (For %%G in (!$L!)Do (Set "%%~G" > Nul &Set /A "#$L+=1"))Else Set $L="
Set "Div=---------------------------------------------------------------------------------------------"
Set "MENU=Echo/!Div!&(For /F "Tokens=1,2 Delims==[" %%X in ('Set $V') Do Set /A "CNT=!#%%~X!" & Set "Array=%%~Y") & Set "Choices=" & (For %%A in (!ARRAY!)Do For /L %%U in (1 1 !CNT!)Do Set "Choices=!Choices!%%U"&For %%S in ("!%%~A[%%U]!")Do Echo/%%~A[%%U] %%~S !%%~S!)&Echo/[E]xit&Echo/!Div!"
rem // ACTION/E Macro to utilise the value of an Array Element
Set "ACTION/E=For /F "Delims=" %%I in ('Choice /N /C:!Choices!E')Do IF "%%I"=="E" (Endlocal&Endlocal&Goto :Eof)Else For %%A in ("!Array![%%I]")Do $M !%%~A!"
rem // ACTION/S Macro to utilise a value assigned to the value of an Array Element (Sub value)
Set "ACTION/S=For /F "Delims=" %%I in ('Choice /N /C:!Choices!E')Do IF "%%I"=="E" (Endlocal&Endlocal&Goto :Eof)Else For %%A in ("!Array![%%I]")Do For %%O in ("!%%~A!")Do $M !%%~O!"
Setlocal EnableExtensions EnableDelayedExpansion
rem // Define associated variables between recipients and servers to enable Access to the values from indexed variables
%List/D/V:$L=Users%"recipient[1]=Person 1" "recipient[2]=Person 2" "recipient[3]=Person 3" "recipient[4]=Person 4"
%List/D/V:$L=Servers%"Person 1=/server:ECRCL" "Person 2=/server:ECRCB" "Person 3=/server:ECRCCI" "Person 4=/server:ECRCCO"
:Loop
CLS
%MENU:$V=Users%
rem // examples of different command usage for ACTION macros. $M is substituted with the required command/s to executed on the value retrieved from the array
rem ::: %ACTION/E:$M=Echo/%
Set "Input="&Set /P "input=Enter Message: "
rem ::: if not "!input!"=="" ((If /I "!input!"=="E" (Exit /B 0)Else Echo/Select Recipient & %ACTION/S:$M=Echo/!Msg!% !input! 2> Nul) || Echo/!Msg! not installed)Else Echo/Input required
if not "!input!"=="" ((If /I "!input!"=="E" (Exit /B 0)Else Echo/Select Recipient & %ACTION/S:$M=!Msg!% !input! 2> Nul) || Echo/!Msg! not installed)Else Echo/Input required
Pause
Goto :Loop
The above has been modified to make the macro's more Generic for different Menu usages. The $M substring of the ACTION macros is substituted with the command to be executed on the value returned through choice selection for the selected index
So i've been looking at articles to see how to get this to work but everything has been going over my head. I'm trying to create a bat file that finds a game commandline.txt and changes a certain commandline for example a resolution
-width=1280
-height=720
to
-width=800
-height=400
for exmaple
and for it to save as the same .txt
I have written this for an example of code i want to use in a similar fashion and for you to get an idea of what i'm doing
#echo off
:MENU
CLS
echo+
echo 1 - game1
echo 2 - game2
echo+
echo+
SET /P MainMenuInput=Enter an option and press ENTER:
if %MainMenuInput% == 1 (
findstr "" "X:\game1\commandline.txt"
echo.%str%
set str=%str:-width=1280 -height=720=-width=800 -height=400%
echo.%str%
)
GOTO :MENU
if %MainMenuInput% == 2 (
findstr "" "X:\game2\commandline.txt"
echo.%str%
set str=%str:-width=1280 -height=720=-width=800 -height=400%
echo.%str%
)
GOTO :MENU
basically i have 2 games - i select number 1 which is game 1 and then it should change the width and height
So if i change it to this, it still doesn't work
#echo off
:MENU
CLS
echo+
echo 1 - Dev_NG
echo 2 - Dev_NG-Live
echo+
echo+
SET /P MainMenuInput=Enter an option and press ENTER:
if %MainMenuInput% == 1 (
set "search=-width=1280"
set "replace=-width=800"
set "textFile=%SettingFile%.txt"
for /f "delims=" %%i in ('type "%X:\game1\commandline.txt%" ^& break ^> "%X:\game1\commandline.txt%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
>>"%textFile%" echo(!line!
endlocal)
I'm making my own console based off batch because I want more then what cmd offers but have the key features that batch has.
One of the most important things is to prompt the user for the command:
:prompt
#echo off
title JDOS command line
echo.
echo.
SET /P command="%FDIR%>"
rem SECTIONS/COMMANDS
rem /I means the if statement is not case-sensitive. USE IT AT ALL TIMES!
if /I "%command%"=="add" goto add
if /I "%command%"=="subtract" goto subtract
goto prompt
(This is just a small portion of all the options but you get the idea)
:add
title Calculator/Add
SET /P Add_A=Please enter the first number:
SET /P Add_B=Please enter the second number:
SET /A sum=%Add_A% + %Add_B%
echo The sum is %sum%
timeout /t 10 >nul
goto prompt
But this is timewasting and sort of idiotic (at least in my opinion).
So, can I execute goto add without the user pressing enter ?
Edit:
I'm thinking an approach similar to CHOICE but with the option to have more than 1 key be pressed (so for example instead of 1/2/3/4/ it would be restart/shutdown/lock/logoff/
I modified my accepted answer at this post and adjusted it for this request. Here it is:
#echo off
setlocal EnableDelayedExpansion
set "commands=add subtract"
for %%a in (%commands%) do set "com[%%a]=1"
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"
set "command="
:nextKey
set "key="
for /F "delims=" %%K in ('xcopy /W "%~F0" "%~F0" 2^>NUL') do if not defined key set "key=%%K"
if "!key:~-1!" equ "!CR!" goto endCommand
if "!key:~-1!" equ "!BS!" (
if defined command (
set "command=%command:~0,-1%"
set /P "=.!BS!!BS! !BS!!BS!" < NUL
)
) else if "!key:~-1!" neq " " (
set "command=%command%!key:~-1!"
set /P "=!key:~-1!" < NUL
if defined com[!command!] goto endCommand
)
goto nextKey
:endCommand
echo/
echo/
echo command read: "%command%"
Note: The mechanism used in this method does not allow to insert spaces! This code should be modified in large parts in order to read spaces.
If I were to create a condition where a user selects a directory by number, how would I test that to make sure it’s valid?
In other words, if a user were prompted:
C:\Program Files
C:\Userdata
Please select a directory: 3
In this unique scenario, how can I test against that and inform the user that 3 is a wrong selection and then loop back to the sub-routine?
I’ve sort of hit a dead end as I thought the “if not exist” would work.
I’ve tried the following without success:
If %errorlevel% equ 1 (command) else (command)
If errorlevel 1 (command) else (command)
If not exist !acctDir!!userDir! (command) else (command).
This is what I have:
:dir
echo.
set c=0
For /f %%a in ('dir !acctDir! /B /A:D') do (
set /a c+=1
echo !c! %%a >>!log!
echo !c! %%a
set dir!c!=%%a
)
echo.
set /p userIn=" Please select a directory [1-!c!]: "
set userDir=!dir%userIn%!
echo ***DEBUG*** Path=[!acctDir!\!userDir!]
pause
if not exist "!acctDir!\!userDir!" (
echo.
echo That is not a valid selection. Please try again. >>!log!
echo That is not a valid selection. Please try again.
echo.
ping 127.0.0.1 -n 3 -w 1000 >nul
cls
goto dir
) else (
echo.
echo You selected !userDir! for your data retrieval. >>!log!
echo You selected !userDir! for your data retrieval.
echo.
ping 127.0.0.1 -n 3 -w 1000 >nul
goto string
)
)
When I do some DEBUG testing to echo out the path before the IF statement is ran I get:
1 Jan_14_2014_12_49_11_900PM
2 Jan_20_2014_6_56_55_953PM
Please select a directory [1-2]: 3
***DEBUG*** Path=[x:\101004357\]
Press any key to continue . . .
So it returns a path as having the account number but not the sub-directory because of obvious reasons as input 3 is nothing. However, IF NOT EXIST should be followed then, right?
I don’t think Windows knows the numbers are related to the sub-directories?
So, I need a condition stating, IF NOT EXIST any subdirectory (which I thought would be the variable !userDir!). But the !userDir! is being assigned as nothing, so this is why it’s not working. Then I think I would need to get a list of the sub-directories to run this statement against.
**This is just 1 of 12 sub-routines, so these are the correct variables.
Any idea of how I can complete this task?
I was able to resolve the issue by solving the issue if there was a NULL output. Setting the variable around brackets and setting it to equal the null output surrounded by empty brackets allows me to test against the user input.
Simply did the following:
if [!userDir!]==[] (
echo.
echo That is not a valid selection. Please try again. >>!log!
echo That is not a valid selection. Please try again.
echo.
ping 127.0.0.1 -n 3 -w 1000 >nul
cls
goto dir
) else (
echo.
echo You selected !userDir! for your data retrieval. >>!log!
echo You selected !userDir! for your data retrieval.
echo.
ping 127.0.0.1 -n 3 -w 1000 >nul
goto string
)
)
Try this:
#echo off
setlocal Enabledelayedexpansion
set c=0
set "acctDir=U:\scripts\batch"
For /f %%a in ('dir !acctDir! /B /A:D') do (
set /a c+=1
echo !c! %%a
set dir!c!=%%a
set valid=!valid! !c!
)
:StartOver
set /p userIn=" Please select a directory [1-!c!]: "
set userDir=!dir%userIn%!
REM echo valid=%valid%
for %%a in (%valid%) do (
if %userIn% NEQ %%a (
set txt=!userIn! is not a valid selection. Please try again.
) ELSE (
set txt=You selected !userDir! for your data retrieval.
Goto :out
)
)
:out
If "%txt:~0,3%" EQU "You" Echo %txt%
if "%txt:~0,3%" NEQ "You" Echo %txt% & goto :StartOver
This should work: The trailing backslash tests only for a folder and not for a filename.
If not exist "!acctDir!\!userDir!\" (command) else (command)
#ECHO OFF
SETLOCAL
SET acctdir=.
:: remove variables starting $
FOR /F "delims==" %%a In ('set $ 2^>Nul') DO SET "%%a="
SET "$alphabet=0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
FOR /f "delims=" %%a IN ('dir "%acctDir%" /B /A:D') DO CALL :setchoices "%%a"
IF NOT DEFINED $_%$alphabet:~0,1% GOTO :EOF
FOR /f "tokens=2*delims=_=" %%a IN ('set $_') DO ECHO(%%a : %%b
choice /c %$$% /m "Choose from menu "
SET /a chosen=%ERRORLEVEL%-1
CALL SET $$=%%$$:~%chosen%,1%%
CALL SET $$=%%$_%$$%%%
ECHO CD "%acctDir%\%$$%"
GOTO :EOF
:setchoices
FOR %%i IN (%$alphabet%) DO IF NOT DEFINED $_%%i (
SET "$_%%i=%~1"
SET "$$=%$$%%%i"
GOTO :EOF
)
GOTO :eof
This works - I used . as acctdir for testing. Your choice of letters and numbers for choicenames in $alphabet
Target directory just echoed - remove the echo before the cd to activate.
I have recently started to learn how to make batch files. I have a folder that contains bunch of internet related log files. When I run the .cmd file (located in the same folder) I want it to be able to find out how many log files are in the folder and make a numbered menu from it. So lets say there are twenty files in the folder, then the user must be able to select from 1 to 21. 21 will close the batch file. Here is what I have done so far:
#echo off
setlocal enableextensions enabledelayedexpansion
set RawData1=TempData%random%.tmp
set FileCtr=0
:MAIN
dir *.log /b | findstr /i /n ".log" > %RawData1%
for /f "tokens=1 delims=:" %%a in (%RawData1%) do set FileCtr=%%a
set /a ExitCode=%FileCtr% + 1
set UserChoice=%ExitCode%
echo.
echo +++++++++++++++++++++++++++
echo Weblog File Viewer
echo +++++++++++++++++++++++++++
for /f "tokens=1-2 delims=:." %%a in (%RawData1%) do echo %%a. %%b
echo %Exitcode%. To Quit.
set /p UserChoice= Choose item number from menu (%UserChoice%):
echo\
echo user entered: %UserChoice%
pause
:THEEND
del /q %RawData1%
So what this batch file can do for now is that it figures out the number of log files and makes a numbered menu from it. Of course it won't show the filetype which is how I wanted it. So "Kelley-Blue-Book.log" for example is shown only as "Kelley-Blue-Book". However, if the user selects say number 4 from the list the program will terminate because I couldn't figure out how to make it actually open the desired log file using notepad.
This should do what you want:
#echo Off
setlocal EnableDelayedExpansion
set "Count=0"
pushd "%~dp0"
echo.
echo +++++++++++++++++++++++++++
echo Weblog File Viewer
echo +++++++++++++++++++++++++++
for %%A in (*.log) do (
set /a "Count+=1"
set "Menu[!Count!]=%%~fA"
set "Number= !Count!"
echo !Number:~-3!. %%~nA
)
set /a "Count+=1"
set "Number= %Count%"
echo %Number:~-3%. To Quit.
:Prompt
set "UserChoice="
set /p "UserChoice= Choose item number from menu (%Count%):"
if not defined UserChoice goto Prompt
set "UserChoice=%UserChoice:"=%"
if "%UserChoice%"=="%Count%" goto Done
for /f "tokens=1,* delims==" %%A in ('set Menu') do (
if /i "Menu[%UserChoice%]"=="%%~A" (
notepad "%%~fB"
set "UserChoice="
)
)
if defined UserChoice echo Invalid Choice.
goto Prompt
:Done
popd
endlocal
exit /b 0
Let me know if you want any explanations.
#echo off
setlocal enableextensions
set RawData1=TempData%random%.tmp
rem Get numbered list of files
dir /b "*.log" | findstr /i /n ".log" > %RawData1%
rem We could use 0 as exitCode,
rem but to keep original behaviour
rem lets count the number of files
for /F "tokens=*" %%f in ('type %RawData1% ^| find /c /v "" ') do set /A ExitCode=%%f + 1
if %ExitCode%==0 (
echo No log files
goto endProcess
)
rem show menu
for /f "tokens=1-2 delims=:." %%a in (%RawData1%) do echo %%a. %%b
echo %Exitcode%. To Quit.
set UserChoice=%ExitCode%
set /p UserChoice= Choose item number from menu (%UserChoice%):
if "%UserChoice%"=="" goto :EOF
if "%UserChoice%"=="%ExitCode%" goto endProcess
rem Search indicated file in list
set SelectedFile=
for /f "tokens=2 delims=:" %%f in ('findstr /B "%UserChoice%:" %RawData1%') do set SelectedFile=%%f
if "%SelectedFile%"=="" (
echo Incorrect selection
goto endProcess
)
if not exist %SelectedFile% (
echo File deleted
goto endProcess
)
notepad %SelectedFile%
:endProcess
del /q %RawData1%