# Solved: Batch file to prompt user for a choice of operations



## zappelectric19 (Aug 6, 2009)

How can I have this batch file prompt the user to select one of the choices below?
1. Terminate program at this point.
2. Perform this operation.
3. Skip this operation and go to the next operation.

Thank you.

```
@ECHO OFF
echo "Enter FolderName"
set /p FolderName=
 
xxcopy "D:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "D:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE D 
SLEEP 2000

xxcopy "F:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "F:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE F
echo %FolderName% REPLACEMENT IN Program Files ON LOCAL COMPUTER COMPLETE.
::-----------------------------------------------------------------------
:: NEED A PROMPT HERE TO SELECT ONE OF THE FOLLOWING
:: 1. TERMINATE PROGRAM
:: 2. REPLACE %FolderName% IN Program Files ON DRIVE H
:: 3. SKIP DRIVE H AND GO TO REPLACE %FolderName% IN Program Files ON DRIVE H
::-----------------------------------------------------------------------

echo TO TERMINATE CLOSE THIS WINDOW. 
echo TO CONTINUE REPLACEMENT OF %FolderName% ON REMOTE DRIVE H 
PAUSE

xxcopy "H:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "H:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE H
PAUSE
```


----------



## TheOutcaste (Aug 8, 2007)

Choice 3 makes no sense, you can't both skip drive H and replace on drive H; Is that supposed to be Skip drive H ande replace on drive I?

```
:_Ask
Set _Resp=
Echo.
Echo. 1. TERMINATE PROGRAM
Echo. 2. REPLACE %FolderName% IN Program Files ON DRIVE H
Echo. 3. SKIP DRIVE H AND GO TO REPLACE %FolderName% IN Program Files ON DRIVE H
Echo.
Set /P _Resp=Enter your choice (1, 2, 3): 
If "%_Resp%"=="" Goto _Ask
If "%_Resp%"=="1" Goto :EOF
If "%_Resp%"=="2" Goto ReplaceH
If Not "%_Resp%"=="3" Goto _Ask
:: This is the code for choice 3
Goto Nextsection
:ReplaceH:: Code to REPLACE %FolderName% IN Program Files ON DRIVE H
```


----------



## zappelectric19 (Aug 6, 2009)

My Bad! I apologize for the typographical error. The line should have been:
":: 3. SKIP DRIVE H AND GO TO REPLACE %FolderName% IN Program Files ON DRIVE M"

I have found a way to make the script do what I wanted. My script isn't very elegant I am sure there are better ways to write a script to achieve this. But although it may be primitive, it does what I wanted.

New Copy.bat
-----------------------------------------------------------------
@ECHO OFF
echo "Enter FolderName"
set /p FolderName=

xxcopy "D:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "D:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE D 
SLEEP 2000

xxcopy "F:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "F:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE F
echo %FolderName% REPLACEMENT IN Program Files ON LOCAL COMPUTER COMPLETE.

::-----------------------------------------------------------------

setlocal

echo T - TERMINATE Operation
echo P - PROCESS Drive H
echo S - SKIP Drive H Continue on to Drive M

set /p option=[1,2,3]?

if "%option%"=="T" goto TERMINATE
if "%option%"=="P" goto PROCESS_H
if "%option%"=="S" goto SKIP

echo Invalid option
goto :TERMINATE

::-----------------------------------------------------------------

ROCESS_H

xxcopy "H:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "H:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE H
SLEEP 2000

goto SKIP

:SKIP

::-----------------------------------------------------------------

setlocal

echo T - TERMINATE Operation
echo P - PROCESS Drive H

set /p option=[1,2]?

if "%option%"=="T" goto TERMINATE
if "%option%"=="P" goto PROCESS_M

echo Invalid option
goto :TERMINATE

::-----------------------------------------------------------------

ROCESS_M

xxcopy "M:\Program Files\%FolderName%\" /RMDIR /YY
xxcopy "C:\Program Files\%FolderName%\" "H:\Program Files\%FolderName%\" /KS /H /E /YY /R

echo REPLACED %FolderName% IN Program Files ON DRIVE M
goto :TERMINATE

:TERMINATE
echo TERMINATING PROGRAM IN 10 SECONDS
SLEEP 10000
EXIT


----------

