views:

470

answers:

3

I have a game that uses this file structure:

GAME FOLDER ->data ->data->run.bat

I want to put a shortcut to run.bat in GAME FOLDER, but if I move it, or someone else installs it it won't work because the target is wrong. Is there a way to make the target and "start in" relative to GAME FOLDER?

+1  A: 

If you can set a system variable (something like %MyGameFolder%), then you can use that in your paths and shortcuts, and Windows will fill in rest of the path for you (ie %MyGameFolder%\data\MyGame.exe).

Here is a small primer. You can either set this value via a batch file, or you can probably set it pro grammatically if you share how you're planning to create your shortcut.

rwmnau
For example, my shortcut for Notepad points to "%SystemRoot%\system32\notepad.exe", which automatically resolves whatever the equivalent of C:\Windows is on your computer.
rwmnau
A: 

Or you could have the batch change the Current Working Directory (CD)?

Vincent
This is what I would recommend also. On NT5+ at least, you can get the path to the currently running batch file with %~dp0 (If command processor extensions are on, and the are by default, but you should call setlocal at the start of your batch to make sure)
Anders
A: 

Try using Relative (a windows command-line app)

http://www.csparks.com/Relative/index.html

Basically, a shortcut could have a relative link, but Windows gives no way to actually make one.

TimDC