Batch file menu question,Newbie here...

March 9, 2012 at 22:28:48
Specs: Windows XP
I want to create a batch that have selection inside.
This is batch i make it (I feel stupid honestly =.=)

@ECHO OFF
CD\
CLS

:MENU
CLS

ECHO ============= MENU NAME =============
ECHO -------------------------------------
ECHO 1. C:
ECHO 2. D:
ECHO 3. E:
ECHO 4. F:
ECHO 5. G:
ECHO 6. H:
ECHO 7. I:
ECHO -------------------------------------
ECHO 8. J:
ECHO 9. K:
ECHO 10. L:
ECHO 11. M:
ECHO 12. N:
ECHO 13. O:
ECHO 14. P:
ECHO -------------------------------------
ECHO 15. Q:
ECHO 16. R:
ECHO 17. S:
ECHO 18. T:
ECHO 19. U:
ECHO 20. V:
ECHO 21. W:
ECHO -------------------------------------
ECHO 22. X:
ECHO 23. Y:
ECHO 24. Z:
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO :MENU
IF /I '%INPUT%'=='2' GOTO :MENU
IF /I '%INPUT%'=='3' GOTO :MENU
IF /I '%INPUT%'=='4' GOTO :MENU
IF /I '%INPUT%'=='5' GOTO :MENU
IF /I '%INPUT%'=='6' GOTO :MENU
IF /I '%INPUT%'=='7' GOTO :MENU
IF /I '%INPUT%'=='8' GOTO :MENU
IF /I '%INPUT%'=='9' GOTO :MENU
IF /I '%INPUT%'=='10' GOTO :MENU
IF /I '%INPUT%'=='11' GOTO :MENU
IF /I '%INPUT%'=='12' GOTO :MENU
IF /I '%INPUT%'=='13' GOTO :MENU
IF /I '%INPUT%'=='14' GOTO :MENU
IF /I '%INPUT%'=='15' GOTO :MENU
IF /I '%INPUT%'=='16' GOTO :MENU
IF /I '%INPUT%'=='17' GOTO :MENU
IF /I '%INPUT%'=='18' GOTO :MENU
IF /I '%INPUT%'=='19' GOTO :MENU
IF /I '%INPUT%'=='20' GOTO :MENU
IF /I '%INPUT%'=='21' GOTO :MENU
IF /I '%INPUT%'=='22' GOTO :MENU
IF /I '%INPUT%'=='23' GOTO :MENU
IF /I '%INPUT%'=='24' GOTO :MENU
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-24] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======


:MENU
CLS

ECHO ============= MENU NAME =============
ECHO -------------------------------------
ECHO 1. Remove Autorun.inf
ECHO 2. Remove Thumbs.db
ECHO 3. Remove SVI
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO :Selection1
IF /I '%INPUT%'=='2' GOTO :Selection2
IF /I '%INPUT%'=='3' GOTO :Selection3
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-3] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:Selection1

echo y|cacls autorun.inf /T /P Everyone:F
echo y|del /s autorun.inf
pause

:Selection2

echo y|cacls "System Volume Information" /T /P Everyone:F
echo y|rd /s "System Volume Information"
pause

:Selection3

del / s / ar / as / aa / aa Thumbs.db

:Quit
CLS

ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE>NUL
EXIT

first, i want select DRIVE, even though i selected, still inside drive C:...
This information i was search on internet, i just modify myself and i'm just starting to learn how to create selective bath, will all the expert help me or give me suggestion?guide me please >.<


See More: Batch file menu question,Newbie here...

Report •


#1
March 9, 2012 at 22:37:39
@echo off
set cnt=
set errmsg=echo invalid number - select again^&^&goto select
setlocal enabledelayedexpansion
for /f "delims=" %%d in ('fsutil fsinfo drives^|find ":"') do (
set tmp=%%d&&set tmp=!tmp:\=!&&set tmp=!tmp:Drives: =!
for /f "delims=" %%e in ('fsutil fsinfo drivetype !tmp!') do (
set /a cnt+=1&&echo !cnt!. %%e&&set ___var___!cnt!=%%e
)
)

:select
set drv=&&set err=&&set test=
set /p drv=please select your drive.
if not defined drv goto select
if "%drv:~0,1%"=="0" %errmsg%
for /f %%b in ('set /a %drv%*2 2^>^&1 1^>nul') do set err=%%b
if defined err %errmsg%
if %drv% gtr %cnt% %errmsg%
set /a test=%drv%*2>nul
if %test%==0 %errmsg%
set str=!___var___%drv%!
for /f %%c in ("%str%") do set drv=%%c
set cnt=&&set err=&&set test=&&set errmsg=
for /l %%g in (1,1,%cnt%) do set var%%g=
setlocal disabledelayedexpansion
echo the drive you selected is %drv%
pause

:MENU
CLS

ECHO ============= MENU NAME =============
ECHO -------------------------------------
ECHO 1. Remove Autorun.inf
ECHO 2. Remove Thumbs.db
ECHO 3. Remove SVI
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.

SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO :Selection1
IF /I '%INPUT%'=='2' GOTO :Selection2
IF /I '%INPUT%'=='3' GOTO :Selection3
IF /I '%INPUT%'=='Q' GOTO Quit

CLS

ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-3] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE > NUL
GOTO MENU

:Selection1

X:
echo y|cacls autorun.inf /T /P Everyone:F
echo y|del /s autorun.inf
pause

:Selection2

X:
echo y|cacls "System Volume Information" /T /P Everyone:F
echo y|rd /s "System Volume Information"
pause

:Selection3

X:
del / s / ar / as / aa / aa Thumbs.db

:Quit
CLS

ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======

PAUSE>NUL
EXIT

This is another one i done (search information from internet also)
its can scan what drive you having now, although i select specified drive, still never change...help =(

P.S. Sorry for my improper english =P


Report •
Related Solutions


Ask Question