Register
Handmade Hero»Forums»Code»How can .exe use assets from another directory
66 posts
How can .exe use assets from another directory
6 months ago Edited by C_Worm on Jan. 3, 2020, 8:52 p.m. Reason: Initial post
Hey!

Im wondering if there is a way for my executable in my \build directory to find assets like textures (.jpg, .png) etc
that are NOT in the same directory as the executable.

is there some compiler switch?

Or does the assets always have to be in the same directory as the executable?
Simon Anciaux
817 posts
How can .exe use assets from another directory
6 months ago
To do that you generally use the working directory plus relative paths.

For example if you can launch the executable from a command line, you CD to the directory you want to be the working directory and launch your executable from there.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
rem Executable is in D:\bin\
rem I want to launch it from D:\temp\

C:\> D:
D:\> CD temp
rem "D:\temp" is now the working directory (from were the program will execute).
D:\temp> ..\bin\executable.exe

rem Using "xxx.png" in the code of the program will search for the file in "D:\temp\".
rem You can use "path\to\a\sub\folder\xxx.png" in the code to access a sub folder of the working directory.
rem You can use "..\" in the code to move up the path. For example "..\parent\path\xxx.png" to access "D:\parent\path\xxx.png".


If you use Visual Studio to launch you program you can set the working directory in the project settings.

If you create a Windows Shortcut you can set the working directory in the "Start in" field.