Archived

This topic is now archived and is closed to further replies.

Simple file loading question

This topic is 5315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I go about loading/using files that are in a different directory than my program executable? Eg: I have a main game folder with the executable, and this program needs to load files (eg: bitmaps) from another directory, which is located in the folder "Graphics". How would I go about this? Any help would be great (btw, I''m using C++)

Share this post


Link to post
Share on other sites
Use "..\" to go up a level, and you use the folder name, for example "Graphics\" to go into directories. Or you can use the full path, for example "C:\Blah\Bleh\Blergh.bmp", but you shouldn't use this, unless you are sure of the path, if you intend on using the program on different machines, as where the executable is placed could differ.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on May 28, 2003 7:11:05 AM]

Share this post


Link to post
Share on other sites
Hey thanks, but I can''t seem to get it working...
Maybe I didn''t understand you, this is what I''ve done:

LoadSomething("..\Graphics\example.bmp");

Please, how exactly does the syntax look like?

Share this post


Link to post
Share on other sites
You only use ".." to go up a level. If you have your executable in one folder, and then your bitmaps in a Graphics folder which is a subdirectory of this, then, as already mentioned, do something like:

LoadSomething("Graphics\graphic.bmp");

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

Share this post


Link to post
Share on other sites
Thanks guys, got it working

Just one more thing (and I hope I don''t sound too picky),
but I noticed that the backslash (\) didn''t work when writing to directories, but the foward slash (/) does work.

Lektrix, did you just make a mistake by using back slashes instead of foward slashes??

Anyway I know it doesn''t matter and you probably just mixed ''em up... Thanks again.

Share this post


Link to post
Share on other sites
quote:
Original post by chacha8
Lektrix, did you just make a mistake by using back slashes instead of foward slashes??

Oops. That should be "\\", as in:

LoadSomething("Graphics\\graphic.bmp");

Bleh, escape sequences. But yeah, forward slash will work as well, although I like to use back slashes for files.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on May 28, 2003 9:58:13 AM]

Share this post


Link to post
Share on other sites
I think it depends on the compiler you use. Mingw32/gcc, coming from the *nix world, takes forward slashes ''/''. I don''t know about vc++ or other compilers.

A single backslash will of course escape the next character and therefore not work.

I always use forward slashes, in a desperate attempt to keep things portable


My Wonderful Web Site (C++ SDL OpenGL Game Programming)

I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites