Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

peter86

Take out the filename of a path

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

If I have this path: "C:\Temp\test.txt", then I want to separate the path in two strings, "C:\Temp\" and "test.txt". I have the path i a WCHAR. So how do I code this?

Share this post


Link to post
Share on other sites
Advertisement
You can do it with the STL, but I''m not very good with those things. You could std::reverse the sequence, std::find the first "\\" in the reversed sequence, and use std::string::substr with string::size - n to get the path.

If someone knows how to get rid of the ugliness and the inefficiency with standard algorithms or with boost, I''d be interested to know it.

Cédric

Share this post


Link to post
Share on other sites
cedricl: Since you want to find the first occurence of ''\'' from the rear, use std::string::find_last_of:

string str = "c:\\temp\\test.txt";
int p0 = str.find_last_of( "\\" );
string path, filename;
path = str.substr( 0, p0-1 );
file = str.substr( p0+1 );

Share this post


Link to post
Share on other sites

  • 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!