I would like to create a batch file where I can save text in a menu and then open that info again.
i want to be able to open it like a file in a menu after i press enter while in the batch file sort of like this as the menu
://
title //
cls
echo.
echo 1) saved data 1
echo 2) saved data 2
echo.
set /p menu="Option:"
if %menu%==1 goto :(open saved data 1 in batch file)
if %menu%==2 goto :(open saved data 2 in batch file)
You can read from a file with a for /f loop if %menu%==1 ( for /f "tokens=*" %%i in ("file1.txt") do set saved_data=%%i )If you mean actually opening the file you can use something like this:
if %menu%==1 ( start file1.txt )Tony
could someone please redo this so i can save data and then see taht data / text in the same batch file. ://
title //
cls
echo.
set /p in="> "
>>file1.txt echo %in%
:open data
title test
cls
echo.
echo 1) open file 1
echo.
set /p menu="Option:"
if %menu%==1 (
for /f "tokens=*" %%i in ("file1.txt") do set saved_data=%%i
)
There seems to be quite a bit of ambiguity in this setup. First, is there only one line, or multiple lines, in these files? The "set /p" only allows one line, so I will go with that assumption (1 line per file). Second, what do you want to do (if anything) besides display the data? Do you want to allow modification (perhaps in a "sub-menu" option).
Oh well, here's one way that might serve:
::===== begin batch snippet
:open data
title test
:: this is the upper limit, set as var. to allow for changes.
set last=2
set op=save to
:gather data
set /p data=Enter your data:
:store data
call :menu
>file%menu%.txt echo %data%
:open data
set op=open
call :menu
if not exist file%menu% goto :error
for /f "tokens=*" %%i in (file%menu%.txt) do set saved_data=%%i
echo data from file%menu%:
echo %saved_data%
goto :eof
:menu
cls
echo.
for /L %%i in (1,1,%last%) do echo %%i) %op% file %%i
echo.
set /p menu="Option:"::==== end batch
Although this doesn't do very much. You might also want to enforce the restriction on 1 to %last%, and not greater or less than with another for-loop:
for /L %%i in (1,1,%last%) do if %menu% equ %%i goto :ok
goto :error
:ok
(proceed with file-open and read operation)but I don't know the background, so i just left that out to keep things simpler.
I still don't get it i just need something simple that i can have 2 menus. 1 to select new data and saved data. The 2nd is a list of saved data (open 2nd menu using the first menu.
Alright, here is my final chapter in this epic saga: ::===== begin batchscript
@echo off & setlocal
set last=0
call :files:main
cls
echo 1) new data
echo 2) view data
echo else: exit
set option=z
set /p option=selection:
if %option% equ 1 goto :new
if %option% equ 2 goto :view
goto :eof:new
set data=
set /p data=data:
if defined data (
>> file%last%.txt echo %data%
set /a last+=1
set msg=Data saved to file%last%
goto :msg
)
goto :main:view
if not exist file1.txt (
set msg=No data has been saved yet
goto :msg
)
set /a e=last-1
for /L %%a in (1,1,%e%) do echo %%a) file%%a.txt
set file=
set /p file=selection:
if exist file%file%.txt (
type file%file%.txt
set msg========= end of data for file%file% =========
) else (
set msg=No file: file%file%.txt
)
goto :msg:files
set /a last +=1
if exist file%last%.txt goto :files
goto :eof:msg
echo.
echo %msg%
pause > nul
goto :main
what about having a batch file so the user name and password have to match :MAIN
cls
echo.
echo Enter your username
echo.
set /p "username= > "
if %username%==Jake goto PASSWORD
if %username%==jake goto PASSWORD
goto ERROR1:ERROR1
echo.
echo The username was not found on the database, please try again.
echo.
pause
goto MAIN:PASSWORD
cls
echo.
echo Enter your password
echo.
set /p "password= > "
if %password%==2459 goto OK
goto ERROR2:ERROR2
echo.
echo The password is incorrect, please try again.
echo.
pause
goto PASSWORD:OK
REM Do your thing here..
cls
echo.
echo Welcome %username%,
echo.
pause
goto :A
