Computer Hope

Microsoft => Microsoft DOS => Topic started by: lionround on October 30, 2015, 09:55:54 AM

Title: Running a batch file from with a batch file not working right
Post by: lionround on October 30, 2015, 09:55:54 AM
I am trying to create a directory based on three variables.  Then I use the "civmd.bat" file to create subdirectories under that in a standardized format. 

Quote
@ECHO OFF
SET /P uname=Please enter your name:
IF "%uname%"=="" GOTO Error
SET /P uname2=Please enter Defendant's Last name:
SET /P caseno=Please enter USA Case Number:
ECHO Hello %uname%, Welcome to DOS inputs!
MD "D:\%uname%\%uname2% %caseno%"
copy d:\civmd.bat "D:\%uname%\%uname2% %caseno%"
cd "D:\%uname%\%uname2% %caseno%"
call "D:\%uname%\%uname2% %caseno%\civmd.bat"
PAUSE
GOTO End
:Error
ECHO You did not enter your name! Bye bye!!
:End

Everything works as planned except that the civmd.bat file that is being "called" runs in whatever directory I have this input.bat file.  Not in the "D:\%uname%\%uname2% %caseno%" directory.
Title: Re: Running a batch file from with a batch file not working right
Post by: Salmon Trout on October 30, 2015, 01:06:09 PM
Is the input.bat stored in a folder on the D drive? The reason I ask is that a CD command will not work if the new directory is on a different drive form the current folder unless you use the /D switch to change the drive, e.g.

Code: [Select]
cd /d "D:\%uname%\%uname2% %caseno%"
Or you can change the drive first:

Code: [Select]
D:
cd /d "D:\%uname%\%uname2% %caseno%"
Title: Re: Running a batch file from with a batch file not working right
Post by: lionround on October 30, 2015, 01:45:27 PM
No, it wasn't.  It was on my c:\temp.  I took it from your question that would matter, so I moved it and it worked.