Sign in to follow this  
Raeldor

Path from filename

Recommended Posts

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

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