Simple file loading question

Started by
6 comments, last by Chacha 20 years, 10 months ago
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++)
Advertisement
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]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
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?
LoadSomething("Graphics/Example.bmp"); should work.

"Skepticism.... that great rot of the intellect." - V.H.
Bah, what does HE know?


Albekerky Software
"Skepticism.... that great rot of the intellect." - V.H.Bah, what does HE know?Albekerky Software
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 ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
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.
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]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
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.
---Just trying to be helpful.Sebastian Beschkehttp://randomz.heim.at/

This topic is closed to new replies.

Advertisement