Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the base name of a file using <filesystem>

Tags:

c++

In the case of a path like: "C:/Dir/foo.txt", the base name of the file would be "foo". I used to be able to do it like this:

#include <filesystem>
using namespace std;
using namespace std::tr2::sys;
...
path p("C:/Dir/foo.txt");
auto base = p.basename();    // base will now be "foo"

This worked when I used visual studio 2013. Now in the newer version (2015) it will not compile giving me the error:

Error C2039 'basename': is not a member of 'std::experimental::filesystem::v1::path'

What is the equivalent function, or the way to do what I need in the new compiler?

like image 869
Eyal K. Avatar asked Oct 20 '25 01:10

Eyal K.


1 Answers

This now appears to be called stem()

Returns the filename identified by the path stripped of its extension.

like image 119
Barmar Avatar answered Oct 21 '25 14:10

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!