1.

Solve : Self Renaming Batch File Help?

Answer»

I WROTE this batch file to test out some stuff I had just learned and I can not figure out why it's not working.

Code: [Select]@ECHO OFF
TITLE Rename Test

:Restart2

IF EXIST Title.txt GOTO Next2

:Restart

CLS
ECHO Please choose a number
ECHO 1-5
ECHO.
Set /P Save=""
IF "%Save%"=="1" goto Next
IF "%Save%"=="2" goto Next
IF "%Save%"=="3" goto Next
IF "%Save%"=="4" goto Next
IF "%Save%"=="5" goto Next
CLS
ECHO Error - Unknown Command
ECHO.
PAUSE
GOTO Restart

:Next

CLS
ECHO %Save% > Title.txt
ECHO Saving . . .
ECHO.
PAUSE
GOTO Restart2

:Next2

Set /p Title= < Title.txt
TITLE %Title%
ECHO Rename Successful!
Echo.
Pause

:Restart2

CLS
ECHO What would you like to Do?
ECHO Restart or Quit?
SET /p Next=""
IF "%Next%"=="Restart" GOTO Next3
IF "%Next%"=="restart" GOTO Next3
IF "%Next%"=="Quit" GOTO Next4
IF "%Next%"=="quit" GOTO Next4
CLS
ECHO Unknown Command
PAUSE
GOTO Restart2

:Next3

CLS
DEL Title.txt
ECHO Restarting . . .
ECHO.
PASUE
GOTO Restart2

:Next4

CLS
DEL Title.txt
ECHO Quitting . . .
ECHO.
PAUSE
EXIT
It creates the file properly and then will delete the file on exit properly, but it skips the renaming step.
Can anybody lend me a hand and help me figure out why?PASUE?

Thank you Salmon!

That doesn't solve the PROBLEM though, it still skips over the renaming part.

You enter a number, it saves the number in a txt file, and then prompts for a restart/quit. Completely SKIPPING over the renaming part.

Any ideas?one possibility is that a number before the redirection symbol tells it to write to a different stream, try it with the redirection at the start of the line:
Code: [Select]>Title.txt ECHO %Save% I know there was a post here in the last week or 2 that explained how to avoid this, but cannot locate it right nowIt creates the file properly, so that's not the problem,

Whatever though, thank you for the help. It was just for fun, to see if i could do it.

I rewrote it much more simplified:
Code: [Select]@ECHO OFF

:Start

TITLE %Title%
IF "%Title%"=="Matt" GOTO Next

CLS
ECHO Enter a title for this .bat:
SET /p Title=""

GOTO Start
Just add some "IF"s to make only certain titles work etc...

I'll just find some way to add on to this to make it more complex.

Thanks again Salmon and gpl!



Discussion

No Comment Found