Batch File

I want to create a batch file where I need to get a path from the user and set it as my base path. There can be three paths:
1. C:\Program Files\Test Folder1
2. C:\Test Folder2
3. Other I would Like to enter

If the user selects first 2 options then the next step is that I want to set that as my base path. If the user selects 3 then the user will enter the path and we need to capture the same and set it as base path.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard QuadlingSenior Software DeveloperCommented:
Here is a batch file which does what you want.
REM Clean up
SET BaseChoice=
SET BaseTest=
SET BasePath=
REM Display the options.
ECHO Choose our base path.
ECHO 1. C:\Program Files\Test Folder1
ECHO 2. C:\Test Folder2
ECHO 3. Enter your own base path.
ECHO 0. Quit
REM Get the choice from the user.
SET /P BaseChoice=Choose from 1, 2 or 3 : 
REM Reduce the entered choice to a single character.
SET BaseTest=%BaseChoice:~0,1%
REM Test the choice made
IF "%BaseTest%"=="0" GOTO :EOF
IF "%BaseTest%"=="1" (
	SET BasePath=C:\Program Files\Test Folder1
	GOTO Done
IF "%BaseTest%"=="2" (
	SET BasePath=C:\Test Folder2
	GOTO Done
IF NOT "%BaseTest%"=="3" GOTO LOOP
SET /P BasePath=Enter your own base path : 
IF EXIST "%BasePath%" GOTO Done
ECHO Your BasePath is %BasePath%

Open in new window

michaelm702Author Commented:
I tried running the code but if I choose option 3 and enter c:\program files as my path it does not accept and if i put c:\bat it accepts. I feel the program is not accepting directory names with space in between them.
Richard QuadlingSenior Software DeveloperCommented:

2008/02/08  9:57:41 C:\>ver

Microsoft Windows XP [Version 5.1.2600]

2008/02/08  9:57:42 C:\>basep
Choose our base path.
1. C:\Program Files\Test Folder1
2. C:\Test Folder2
3. Enter your own base path.

0. Quit
Choose from 1, 2 or 3 : 3
Enter your own base path : C:\Program Files

Your BasePath is C:\Program Files

2008/02/08  9:57:50 C:\>echo %BASEPATH%
C:\Program Files

2008/02/08  9:57:58 C:\>

What OS are you running?
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

michaelm702Author Commented:
C:\bat>call C:\Program Files\imp.exe 'C:\Program' is not recognized as an internal or external command,
operable program or batch file.'

After getting the base directory when i call a exe file in the base folder i get the error "'C:\Program' is not recognized as an internal or external command,operable program or batch file.'"

I am using widows xp professional service pack 2
Richard QuadlingSenior Software DeveloperCommented:
As with all filenames with spaces, you need to put a pair of " around it.

CALL "%BasePath%\imp.exe"

sort of thing.
Richard QuadlingSenior Software DeveloperCommented:
Notice I used ...

IF EXIST "%BasePath%" GOTO Done

in the batch file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.