Batch file to prompt user for a choice of operations

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
steve.marks59
Posts: 4
Joined: 12 Feb 2011 18:25

Batch file to prompt user for a choice of operations

#1 Post by steve.marks59 » 12 Feb 2011 18:32

My OS is XP-PRO SP3

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.

Code: Select all

@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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file to prompt user for a choice of operations

#2 Post by aGerman » 12 Feb 2011 19:20

I'm not familiar with this xxcopy stuff. For that reason I only can give you an idea how it should work. Because you're on XP you have to work with SET /P.

Code: Select all

@echo off &setlocal

echo 1. Terminate program at this point.
echo 2. Perform this operation.
echo 3. Skip this operation and go to the next operation.

:errorLoop
set "choice="
set /p "choice=Enter a number: "
if "%choice%"=="1" goto :eof
if "%choice%"=="2" goto firstOperation
if "%choice%"=="3" goto secondOperation
goto errorLoop

:firstOperation
echo your stuff for the 1st operation

:secondOperation
echo your stuff for the 2nd operation

pause

Regards
aGerman

steve.marks59
Posts: 4
Joined: 12 Feb 2011 18:25

Re: Batch file to prompt user for a choice of operations

#3 Post by steve.marks59 » 13 Feb 2011 03:02

Thanks for the suggestions.

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
-----------------------------------------------------------------

Code: Select all

@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

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

:PROCESS_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

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

:PROCESS_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

Post Reply