Page 1 of 1

Application relative path? [Solved]

Posted: Tue May 20, 2008 7:48 pm
by TnTonly
Okay, another dummy question...

The problem is that I want to use some relative path in my game. In the tutorial I have seen something like this
../../media/xyz.ext
and "../" here means up one level

So if I want to get the current level of my application path, what should I do.
For more specific, I have a folder "media" in a same place as my .exe is. What relative path should I use to access the "media" folder? I have tried "media/xyz.ext" and "/media/xyz.ext" but no can work.

Posted: Tue May 20, 2008 8:14 pm
by Mr. Moxie
After initializing the game, I store the path location of the game executable's working directory.

Code: Select all

m_szExePath					=m_pDevice->getFileSystem()->getWorkingDirectory();
When I load anything using relative paths, I call this member function first.

Code: Select all

void gmMain::SetFilePathToExeDir()
{
//	printf("exe dir=%s\n",m_szExePath);
	GAME->GetDevice()->getFileSystem()->changeWorkingDirectoryTo(m_szExePath.c_str());
}

And I use a path like:

assets2D\azkat\rooidle_north0000.bmp

Hope this helps.

Posted: Tue May 20, 2008 11:23 pm
by MasterGod
Maybe ./your path.. e.g,

Code: Select all

./media/skydomes/skydm1.png

Posted: Wed May 21, 2008 7:09 am
by arras
Forgive me if I am missing here something but "../../media/xyz.ext" IS relative path. Unlike for example "D:/project/media/xyz.ext" which tels absolute path.

I am frequently using media folder in my working directory and line "media/xyz.ext" always works fine.

Are you sure it is path which makes file to fail to load?

Re: Application relative path?

Posted: Wed May 21, 2008 8:00 am
by rogerborg
TnTonly wrote:For more specific, I have a folder "media" in a same place as my .exe is. What relative path should I use to access the "media" folder? I have tried "media/xyz.ext" and "/media/xyz.ext" but no can work.
That should work. If you run it via an IDE though, then the working directory may not be the same as the directory that the .exe is in. e.g. the .exe is put in a "Debug" directory, but the working directory is actually the main project directory.

Posted: Wed May 21, 2008 6:30 pm
by TnTonly
Thanks, that helps! I've always thought that the relative path is used with my Debug directory (that contain the .exe file) since Debug and my project directory is always in the same level and "../media" point to the same folder. So the relative path is for the project folder right?

Thanks all!!!