Application relative path? [Solved]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
TnTonly
Posts: 14
Joined: Mon May 12, 2008 5:14 pm
Location: Hanoi
Contact:

Application relative path? [Solved]

Post 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.
Last edited by TnTonly on Wed May 21, 2008 6:31 pm, edited 1 time in total.
Mr. Moxie
Posts: 48
Joined: Thu Dec 06, 2007 7:55 pm
Contact:

Post 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.
George A Lancaster
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Maybe ./your path.. e.g,

Code: Select all

./media/skydomes/skydm1.png
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post 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?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: Application relative path?

Post 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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
TnTonly
Posts: 14
Joined: Mon May 12, 2008 5:14 pm
Location: Hanoi
Contact:

Post 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!!!
Post Reply