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.
michaelm702Asked:
Who is Participating?
 
Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
Notice I used ...

IF EXIST "%BasePath%" GOTO Done

in the batch file.
0
 
Richard QuadlingSenior Software DeveloperCommented:
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

0
 
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.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
Richard QuadlingSenior Software DeveloperCommented:
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?
0
 
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
0
 
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.
0
All Courses

From novice to tech pro — start learning today.