Link to home
Start Free TrialLog in
Avatar of michaelm702
michaelm702

asked on

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.
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Here is a batch file which does what you want.
@ECHO OFF
:Loop
 
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.
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
 
GOTO Loop
 
:Done
ECHO.
ECHO Your BasePath is %BasePath%

Open in new window

Avatar of michaelm702
michaelm702

ASKER

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

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?
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
As with all filenames with spaces, you need to put a pair of " around it.

CALL "%BasePath%\imp.exe"


sort of thing.
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial