Colored Menu for starting multi task [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Colored Menu for starting multi task [SOLVED]

#1 Post by abc0502 » 17 Apr 2012 03:49

i'm making a batch file to install manual update to an online game so i'm missing one thing,
how can i ask to input to the location of a folder that has that update patches

This is the final Code and working fine Problem solved

Code: Select all

@echo off
Title Fiesta Manual Update Installer V3.0
::======================================================================
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
::======================================================================
mode 60,30
color 0
echo:&echo:&echo:&echo:&echo:&echo:&echo:&echo:&echo:&echo:
echo:     ######## #### ########  ######  ########    ###   
echo:     ##        ##  ##       ##    ##    ##      ## ##   
echo:     ##        ##  ##       ##          ##     ##   ## 
echo:     ######    ##  ######    ######     ##    ##     ##
echo:     ##        ##  ##             ##    ##    #########
echo:     ##        ##  ##       ##    ##    ##    ##     ##
echo:     ##       #### ########  ######     ##    ##     ##
echo:&echo:&echo:&echo:&echo:&echo:
call :color 0f "                         Enter                            "
pause >nul
cls
color 07

::======================================================================
:loop1
echo:&echo:&echo:&echo:&echo:
call :color 07 "            ==================================" &echo:
call :color 07 "            =" & call :color 0d "Fiesta Manual Update Installer" & call :color 07 "=" & echo:
call :color 07 "            ==================================" &echo:&echo:
call :color 0f "             Select An Option" &echo:&echo:&echo:
call :color 0a "                  (1) Auto Install" &echo:&echo:
call :color 0b "                  (2) Install Patches" &echo:&echo:
call :color 0e "                  (3) Install Sharplaunchers" &echo:&echo:
call :color 08 "                  (4) Exit" &echo:&echo:&echo:
set /p "cho1=Option #"
if %errorlevel%==1 cls & goto loop1
if %cho1%==1 goto auto
if %cho1%==2 goto patches
if %cho1%==3 goto sharplaunchers
if %cho1%==4 goto EOF
echo Invalid choice.
cls
goto loop1
::======================================================================
:auto
echo:
call :color 0c "Enter sharp launchers and patches Directory "&echo:
set /p "installpath=Dir:>"
if %errorlevel%==1 cls & goto loop1
call :color 04 "Installing Sharplaunchers and Patches ..."&echo:
if exist "%temp%\log.log" del /F /Q "%temp%\log.log" >nul
ping localhost -n 2 >nul

setlocal enableextensions
set log=%temp%\log.log
for /f "tokens=*" %%c in ('dir /b /on "%installpath%\*.*"') do (
echo %installpath%\%%c >>"%log%"
)
for /f "tokens=*" %%d in (%log%) do (
start "" /w "%%d"
)
msg * Auto Installation Completed.
msg * Please Restart Your Computer so Changes can take Effect.
cls
goto loop1
::======================================================================
:sharplaunchers
echo:
call :color 0c "Enter sharplaunchers Directory "&echo:
set /p "installpath=Dir:>"
if %errorlevel%==1 cls & goto loop1
call :color 04 "Installing Sharplaunchers ..."&echo:
if exist "%temp%\log.log" del /F /Q "%temp%\log.log" >nul
ping localhost -n 2 >nul

setlocal enableextensions
set log=%temp%\log.log
for /f "tokens=*" %%c in ('dir /b /on "%installpath%\*.*"') do (
echo %installpath%\%%c >>"%log%"
)
for /f "tokens=*" %%d in (%log%) do (
start "" /w "%%d"
)
msg * SharpLaunchers Installation Completed.
msg * Please Restart Your Computer so Changes can take Effect.
cls
goto loop1
::======================================================================
:patches
echo:
call :color 0c "Enter patches Directory "&echo:
set /p "installpath=Dir:>"
if %errorlevel%==1 cls & goto loop1
call :color 04 "Installing Patches ..."&echo:
if exist "%temp%\log.log" del /F /Q "%temp%\log.log" >nul
ping localhost -n 2 >nul

setlocal enableextensions
set log=%temp%\log.log
for /f "tokens=*" %%c in ('dir /b /on "%installpath%\*.*"') do (
echo %installpath%\%%c >>"%log%"
)
for /f "tokens=*" %%d in (%log%) do (
start "" /w "%%d"
)
msg * Patches Installation Completed.
cls
goto loop1
::======================================================================
:color
echo off
<nul set /p ".="%DEL% " " >> "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
::======================================================================
Last edited by abc0502 on 19 Apr 2012 12:06, edited 9 times in total.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: specify a directory

#2 Post by foxidrive » 17 Apr 2012 04:46

abc0502 wrote:i'm making a batch file to install manual update to an online game so i'm missing one thing,
how can i ask to input the location of a folder that has that update patches

i tried this to input the location but it keep run the next command directly without waiting for the input so it give errors:

:auto
Echo Enter Directory:
set "variable="
set /p "variable=install>"
if not defined variable goto :auto
Echo Installing Sharplaunchers and Patches ...
ping localhost -n 3 >nul
"%installpath%\SharpLauncher86b.exe"



abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory

#3 Post by abc0502 » 17 Apr 2012 05:52

Thanks alot foxi for your replay but not all the code worked,only this worked

:auto
Echo Enter Directory:
set /p "variable=install>"
Echo Installing Sharplaunchers and Patches ...
ping localhost -n 3 >nul
"%installpath%\SharpLauncher86b.exe"

and it will look like that:

Code: Select all

:auto
Echo Enter Directory:
set /p "installpath=Directory>"
Echo Installing Sharplaunchers and Patches ...
ping localhost -n 3 >nul
"%installpath%\SharpLauncher86b.exe"

it geive errors for not finding the files then goto the start again
thanks :)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory [solved]

#4 Post by abc0502 » 17 Apr 2012 06:04

one more thing :)
is there away to get the files "exe files" names and list them in alphapit order so the command install it one by one
and i don't have to add new patches name to the batch regulary, i tried using for command to get all files names to a log file then launche them one by one but "getting there names from the log file didn't work any idea

i tried using !k's Code for renaming and change it to start files but no luck:

Code: Select all

@echo off &setlocal enableextensions

set /a cnt=0
for /f "delims=" %%a in ('dir /b /on *.txt') do call :ren "%%a"
goto :eof

:ren
for /f "tokens=1" %%b in ('more +%cnt% log.log') do (
   ren %1 "%%b.txt"
   set /a cnt+=1 &goto :eof
)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory

#5 Post by abc0502 » 17 Apr 2012 06:35

I used this but getting the more is not a command error !! :?:

Code: Select all

@echo off
cls
setlocal enableextensions
set path=%userprofile%\desktop\test
set /a cnt=0
for /f "delims=" %%a in ('dir /b /on "%path%\*.*"') do call :ren "%%a"
goto :eof

:ren
for /f "tokens=1" %%b in ('more +%cnt% log.log') do (
   "%%b.cmd"
   set /a cnt+=1 &goto :eof
)
pause

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: specify a directory

#6 Post by !k » 17 Apr 2012 07:16

set folder=%userprofile%\desktop\test

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: specify a directory

#7 Post by foxidrive » 17 Apr 2012 07:29

abc0502 wrote:Thanks alot foxi for your replay but not all the code worked,only this worked


When faced with an issue like this, try separating the function and see if it works.

My code below works fine in a subroutine of it's own.

Code: Select all

@echo off
:auto
Echo Enter Directory:
set "variable="
set /p "variable=install>"
if not defined variable goto :auto
echo "%variable%"
pause


Enter Directory:
install>abc def
"abc def"


abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory

#8 Post by abc0502 » 19 Apr 2012 03:23

Thanks Foxidrive and !k for help :D :D :D
it worked and now i don't have to edit the batch on every new patches for the game
it read the folder containing the patches and make a list in alphapitc order then start every patch at a time.

i will post the code after small changes.
The batch will be in colors :evil:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory

#9 Post by abc0502 » 19 Apr 2012 06:17

The First Code Was Modified with the working code
Last edited by abc0502 on 19 Apr 2012 07:34, edited 3 times in total.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: specify a directory [SOLVED]

#10 Post by foxidrive » 19 Apr 2012 06:23

You will get an error if the user enters nothing.

And %cho1% should be nulled before the set /p or it can take the value it had before the set /p, if enter was pressed.



set /p "cho1=Option #"
if %cho1%==1 goto auto
if %cho1%==2 goto patches
if %cho1%==3 goto sharplaunchers
if %cho1%==4 goto EOF
echo Invalid choice.
cls
goto loop1



Try this:

Code: Select all

@echo off
:auto
set "variable=zzz"
set /p "variable=press enter: "
if not defined variable goto :auto
echo "%variable%"
pause

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory [SOLVED]

#11 Post by abc0502 » 19 Apr 2012 07:01

WOW :roll: i didn't notice that thanks alot foxidrive ,
i changed the code now it work fine
and as u said in your last post i should used it from the begining :)

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: specify a directory [SOLVED]

#12 Post by foxidrive » 19 Apr 2012 07:13

This will not run any program in %%d.

start /w "%%d"


The first pair of quotes in a start command are used for the title.

You need this:

Code: Select all

start "" /w "%%d"

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory [SOLVED]

#13 Post by abc0502 » 19 Apr 2012 07:20

when i add

Code: Select all

if not defined %installpath% goto :loop1

nothing is installed or run
when i delete it every thing start normally why?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: specify a directory [SOLVED]

#14 Post by abc0502 » 19 Apr 2012 07:32

foxidrive wrote:This will not run any program in %%d.

start /w "%%d"


The first pair of quotes in a start command are used for the title.

You need this:

Code: Select all

start "" /w "%%d"

the folder that will be specified will have only patches that will be ordered in alphapitic order then will be run one by on the patches are auto start so the code work fine with this patches

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: specify a directory [SOLVED]

#15 Post by foxidrive » 19 Apr 2012 07:39

abc0502 wrote:when i add

Code: Select all

if not defined %installpath% goto :loop1

nothing is installed or run
when i delete it every thing start normally why?


if not defined installpath goto :loop1


Don't use quotes.

Post Reply