Computer Hope
Microsoft => Microsoft DOS => Topic started by: zask on January 16, 2016, 04:09:55 PM
-
I am trying to make a batch file that creates messages for other batch files. It first ask for a name to name the file it creates. then then asks to display a message which goes into a spinner for 20 loops and then displays if you would like to clear the screen or continue typing. The problem is that every time I type (Y) in the prompt to clear the text of the created batch file, the prompt closes for an unknown reason. can anyone help?
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
color 17
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo ºBatch Text Editorº
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
pause
:Restart2
cls
SET /p "FileName= Enter the name of the file you want to name: "
echo @echo off > %FileName%.bat
echo The file %FileName%.bat was created!
pause
cls
SET X=1
:Restart1
if %X% EQU 1 echo Line (1)
SET /p "Message= Type message here: "
echo echo %Message% >> %FileName%.bat
) ELSE (
SET /a X+=1
)
if !X! EQU 21 goto Reboot
echo Line (%X%)
goto Restart1
:Reboot
echo pause >> %FileName%.bat
SET /p "YN=Would you like to clear the screen? (Y/N): "
if %YN%==Y echo. > %FileName%.bat
if %YN%==y echo. > %FileName%.bat
if %YN%==N echo goto Restart2
if %YN%==n echo goto Restart2
-
Ill be here if anyone can help.
-
Your IF - ELSE block after label Restart1 does not look right. There is no opening parenthesis ending the IF line.
Also not connected to the problem I think:
You did know that you don't need to test separately for upper and lower case?
Instead of this:
If %var%==N bla bla bla
If %var%==n bla bla bla
You can use the /i switch for IF which ignores case:
If /i %var%==N bla bla bla
-
Your IF - ELSE block after label Restart1 does not look right. There is no opening parenthesis ending the IF line.
Also not connected to the problem I think:
You did know that you don't need to test separately for upper and lower case?
Instead of this:
If %var%==N bla bla bla
If %var%==n bla bla bla
You can use the /i switch for IF which ignores case:
If /i %var%==N bla bla bla
no i did not know that, thanks!