|
Answer» Hello everyone. I need some help editing and opening text file using bat.
I need to get something like: you type text in bat file -> it saves to text file
when you need to load text just goto load and type text you entered before -> then it does something
echo yourtext>>fileOk now i have line in the text file how can i see in bat file?
and if [line1 is ....] goto .... how to do it?ok in this example the name of the text file is h, and will work with multiple lines as LONG as one of them is the line.
for /f "tokens=1*" %a in (h.txt) do if "%a"=="example" Goto Test1
remember to add another percent sign if you use this in a batch file, if you use it in the command window you only need to use one percent symbol on the %a tokens, but in a batch file you need two %%a.
you could also use this in an array, for example
for /f "tokens=1* delims=" %%a in (h.txt) do ( call set /a idx=%%idx%%+1 call goto test1 )i am to dum to figure it out how it works Ok i figured out how it works but i need something to show whats in the text file And thx for helpok, you can get information from the file by typing type filename.txtThankyou!By the WAY i want somehow instert lines in to choices if it is POSIBLE...
@ECHO OFF
:Main CLS echo. echo. echo Welcome. echo Chose: echo Save=1 echo Load=2 echo Exit=0 echo.
SET /P MAIN= Chose...
If '%MAIN%'=='1' Goto Save If '%MAIN%'=='2' Goto Load If '%MAIN%'=='0' exit
echo There is no "%MAIN%" in the code... pause CLS Goto Main
:Save CLS echo Lines inside file: echo. type text.txt echo End of file. echo. echo Your text here: SET /P SAVES= Enter save name...
echo %SAVES%>>text.txt echo Saved... pause Goto Main
:Load CLS echo Lines inside file: echo. type text.txt echo End of file. echo. SET /P LOADS= Chose what to load...
IF '%LOADS%'=='[text file 1st line]' goto l1 IF '%LOADS%'=='[text file 2nd line]' goto l2 IF '%LOADS%'=='[text file 3th line]' goto l3 IF '%LOADS%'=='[text file 4th line]' goto l4 IF '%LOADS%'=='[text file 5th line]' goto l5 IF '%LOADS%'=='[text file 6th line]' goto L6 use something similar to the array example i showed you
@echo off set idx=0 for /f "tokens=1* delims=" %%a in (h.txt) do ( call set /a idx=%%idx%%+1 call set e.%%idx%%=%%a )
IF '%LOADS%'=='%e.1%' goto l1 IF '%LOADS%'=='%e.2%' goto l2 IF '%LOADS%'=='%e.3%' goto l3 IF '%LOADS%'=='%e.4%' goto l4 IF '%LOADS%'=='%e.5%' goto l5 IF '%LOADS%'=='%e.6%' goto l6
|