Handmade Hero»Forums»Code
4 posts
How to use relative path in Shortcut's "Start in:" field
Edited by Lootbox on Reason: Initial post
For example, I have the following dirs:
g:\c\env.lnk <--- this is the shortcut for cmd.exe
g:\c\misc\shell.bat <--- call vcvars32.bat and set path
g:\c\src\ <--- .c files


In the "Target:" field of the env.lnk(cmd.exe shortcut):
%windir%\System32\cmd.exe /k "%CD%\misc\shell.bat"

In the "Start in:" field:
%CD%\src

It works fine, except it starts in g:\c, not in g:\c\src
So how to make it work, I want to start in g:\c\src, and I want to use relative path
Simon Anciaux
1051 posts
How to use relative path in Shortcut's "Start in:" field
I don't know about the shorcut, but you could use a batch file instead:

1
2
3
4
5
6
@echo off
call misc\shell.bat
rem Go to the drive containing the batch file.
%~d0
cd src
%windir%\System32\cmd.exe
Mārtiņš Možeiko
2198 posts / 1 project
How to use relative path in Shortcut's "Start in:" field
Or replace "Target" in shortcut to:
1
C:\Windows\System32\cmd.exe /k "%CD%\misc\shell.bat && cd /d %CD%\src"
4 posts
How to use relative path in Shortcut's "Start in:" field
mrmixer
I don't know about the shorcut, but you could use a batch file instead:

1
2
3
4
5
6
@echo off
call misc\shell.bat
rem Go to the drive containing the batch file.
%~d0
cd src
%windir%\System32\cmd.exe


Thanks, but this will nest a new cmd.exe under the original cmd.exe, also can't customize the RGB value of the text, even though I can use "color" command to change color, but it only offer a handful of choices

mmozeiko
Or replace "Target" in shortcut to:
1
C:\Windows\System32\cmd.exe /k "%CD%\misc\shell.bat && cd /d %CD%\src"


Thanks, "&& cd /d %CD%\src" did the trick.
Strange, I can put things like %windir%, %temp%, %userprofile%, etc in the "Start in" field and they all work, but not "%CD%"