Bat script to .exe with relative paths

I know how to convert bat to exe from here, but I have a problem that there are relative paths in the script itself, and there is no way to make them absolute, and the script inside exe is launched in another place.  What can I do?


Solution 1:

To refer to the current path where the batch is beeing executed you can use %~dp0

For exemple:

echo %~dp0

set CurrentPath=%~dp0

  • no need to use double percentage (%%)

Solution 2:

I too thought the %~dp0 trick would work, but since the script runs in a temp folder (according to this answer https://superuser.com/a/868341/618817) it simply doesn't work, it just references an empty temp folder.

The only workaround I've found so far is to include a copy of the whole directory you're referring to in the iexpress wrapper if it's a specific program you're trying to launch. This does slow everything down since every execution of the .exe'd script means that said directory must be uncompressed and copied before the script runs on it. But it's far from ideal if you're trying to dynamically run a script by placing the exe in the correct root folder and executing it, with the intent of using the directories there...

My only other idea is to design the script to somehow take into account launch parameters, but that starts getting incredibly convoluted for a .bat script, even by my standards.