std::experimental::filesystem::path::filename - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::experimental::filesystem::path::filename

From cppreference.com
< cpp‎ | experimental‎ | fs‎ | path

path filename() const; |  | (filesystem TS)

Returns the filename identified by the path.

Equivalent to empty() ? path() : *--end().

### [edit] Parameters

(none)

### [edit] Return value

The filename identified by the path.

### [edit] Exceptions

(none)

### [edit] Example

Run this code

    #include <filesystem>
    #include <iostream>

    int main()
    {
        std::cout << std::fs::path("/foo/bar.txt").extension() << '\n';
        std::cout << std::fs::path("/foo/.bar").extension() << '\n';
        std::cout << std::fs::path("/foo/bar/").extension() << '\n';
        std::cout << std::fs::path("/foo/.").extension() << '\n';
        std::cout << std::fs::path("/foo/..").extension() << '\n';
        std::cout << std::fs::path(".").extension() << '\n';
        std::cout << std::fs::path("..").extension() << '\n';
        std::cout << std::fs::path("/").extension() << '\n';
    }

Output:

    bar.txt
    .bar
    /

    .cc
    .
    ..
    .
    ..
    /

### [edit] See also

extension | returns the file extension path component (public member function) [edit]
stem | returns the stem path component (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/experimental/fs/path/filename&oldid=68599"