How to change working directory to another drive
I am copying a batch file in c:\ or d:\ based on user preference and will set the shortcut properties as below.
I am setting the "Start In" to the location where batch file is there.
But when I launch the shortcut the current working directory is still c:\windows\system32.
Any suggestion please how to set the working directory to Start In folder.
1 Comment
[ + ] Show comment
Answers (4)
Please log in to answer
Posted by:
anonymous_9363
8 years ago
Batch files are executed by the command processor which lives in that folder.
If you need the batch file's "content" to be drive/folder-specific, use "CD /D [path to change to]" in the file.
If you need the batch file's "content" to be drive/folder-specific, use "CD /D [path to change to]" in the file.
Comments:
-
No I didn't mean that.
What I want is to set the working directory to the folder where batch file exists.
If the user is installing the msi to a different drive like some E:\ , the shortcut is getting set as it is with the StartIn option.
But the batch file execution is still taking C:\windows\system32.
This is working file if choose a different folder in C:\ drive itself.
The problem occurs when I change the drive to some other logical drive instead of the primary partition C:\ - ur00361883 8 years ago
Posted by:
anonymous_9363
8 years ago
Posted by:
EdT
7 years ago
Any reason why ROOTDRIVE cannot be used to set the working drive letter? Then all references are automatically adjusted.
Comments:
-
Actually it is setting fine in the shortcut properties..But the batch file is not working..So I kept pause for troubleshooting and when I checked that commadn prompt, it is showing the workign directory to system32 folder instead of the one in "Strat In". - ur00361883 7 years ago
-
Instead of calling the batch file directly, which invokes CMD.EXE from the system32 folder, try calling c:\windows\system32\cmd.exe /c <path to batch file> and see if the start in folder is then correct. If there is still a problem, the solution is to add code to your batch file to identify the drive letter you are running from and then change drive letter and directory to the location that the start in folder should be pointing to. - EdT 7 years ago
-
It is still showing the c:\ drive - ur00361883 7 years ago
Posted by:
Rajendra_447
7 years ago
Yes. We can use ROOTDRIVE and set the value as C:\ or D:\ as per your requirements. Then it will redirect the shortcut directory to the respective drive. It works perfect.
Comments:
-
THanks Rajendra for your inputs..But the issue is not with msi installation.The shortut is showing the startin settings correctly.
But the batch file is not picking the startin folder at runtime. - ur00361883 7 years ago
cd /d "%~dp0" - ur00361883 7 years ago