Sign in to follow this  
Stowelly

C++ fileio accessing subdirectories

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this