Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

Path from filename

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

Is there any function already existing in the windows api or directx that can return a path from a full filename? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Daevaorn
Raeldor, can you explain me, what difference between "full filename" and "file path"?:)


Full filename would be something like...

c:\textures\test.bmp

file path would be...

c:\textures

Rael

Share this post


Link to post
Share on other sites
Oh, ok. If you are programming in C++, there is path class in boost::filesystem
lib.



#include <Boost/filesystem/path.hpp>

namespace fs = boost::filesystem;

//...
fs::path p( "c:\textures\test.bmp" );
std::string path = p.branch_path().string(); //c:\textures
//...



Share this post


Link to post
Share on other sites
Quote:
Original post by Daevaorn
Oh, ok. If you are programming in C++, there is path class in boost::filesystem
lib.



#include <Boost/filesystem/path.hpp>

namespace fs = boost::filesystem;

//...
fs::path p( "c:\textures\test.bmp" );
std::string path = p.branch_path().string(); //c:\textures
//...



Hi, thanks for the reply, sorry for the delay. What is this boost library? Is there nothing in the standard windows library for this?
Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Raeldor
Hi, thanks for the reply, sorry for the delay. What is this boost library? Is there nothing in the standard windows library for this?
Thanks


The boost library is like the STL, but not "standard". You'll find it at www.boost.org

And what's wrong with _splitpath()? Sure, it's not fancy-shmancy, and requires you to jam the drive & path outputs back together, but it works.

Share this post


Link to post
Share on other sites
Quote:
Original post by pragma Fury
Quote:
Original post by Raeldor
Hi, thanks for the reply, sorry for the delay. What is this boost library? Is there nothing in the standard windows library for this?
Thanks


The boost library is like the STL, but not "standard". You'll find it at www.boost.org

And what's wrong with _splitpath()? Sure, it's not fancy-shmancy, and requires you to jam the drive & path outputs back together, but it works.


Ah, my bad... when you were referring to _splitpath I thought you meant you couldn't remember the function name (didn't know functions could start with '_'). I just found the documentation for _splitpath.

Thank you! :)

Share this post


Link to post
Share on other sites
Or you could just grab everything before the last backslash, i.e.

In C++:
std::string filename;
std::string path = filename.substring(0, filename.find_last_of('\\'));


In C:
char *filename;
char path[256];
char *lastBackslash = strchr(filename, '\\');
strncpy(path, filename, lastBackslash - filename + 1);
path[lastBackslash - filename + 1] = '\0';

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!