C++ fileio accessing subdirectories

Started by
3 comments, last by Stowelly 18 years ago
my project directory is getting pretty bloated and im trying to break it down into seperate directories for my media etc, currently im accessing my files like so char* filename = "objList.dat"; which seems to default to the current directory but when i try any of the following to try and access a sub dir it just doesnt load "/media/objList.dat"; "//media//objList.dat"; "\\media\\objList.dat"; im sure this is very simple, but still its doing my head in thanks
http://stowelly.co.uk/
Advertisement
I access my subdirectory files via:
"./[dir]/[file]"

However, it can also depend on your file loading code and whether or not there are any suppositions there about whether files will be found in the same directory as the executable.
Try making the path complete by adding a dot, indicating to start from the curren directory:

"./media/objList.dat"; (for unix-based systems, works on windows as well)
".//media//objList.dat"; (makes no sense, '/' is not an escape character)
".\\media\\objList.dat"; (for windows, double '\\' because '\' is an escape character)

Illco
Quote:Original post by Illco
Try making the path complete by adding a dot, indicating to start from the curren directory:

"./media/objList.dat"; (for unix-based systems, works on windows as well)
".//media//objList.dat"; (makes no sense, '/' is not an escape character)
".\\media\\objList.dat"; (for windows, double '\\' because '\' is an escape character)

Illco

Yes, that will work, but you can also remove the slash:

"media/objList.dat";
"media\\objList.dat";

You can use whatever you like - both should work fine.
excellent cheers for ur help, i knew itd be simple enough
http://stowelly.co.uk/

This topic is closed to new replies.

Advertisement