Jump to content
  • Advertisement
Sign in to follow this  
Stowelly

C++ fileio accessing subdirectories

This topic is 4530 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

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!