Path from filename

This topic is 4879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites
I know there's a newer function for this, but all I can think of is _splitpath.

Share on other sites
Raeldor, can you explain me, what difference between "full filename" and "file path"?:)

Share on other sites
Quote:
 Original post by DaevaornRaeldor, 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 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 on other sites
Quote:
 Original post by DaevaornOh, ok. If you are programming in C++, there is path class in boost::filesystem lib.#include 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 on other sites
Quote:
 Original post by RaeldorHi, 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 on other sites
Quote:
Original post by pragma Fury
Quote:
 Original post by RaeldorHi, 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 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';

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 16
• 14
• 9
• 9
• 9
• Forum Statistics

• Total Topics
632928
• Total Posts
3009268
• Who's Online (See full list)

There are no registered users currently online

×