##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::experimental::filesystem::path::extension

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

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

Returns the extension of the `filename()` identified by the path.

The extension is the substring between the last `.` character and the end of the filename. The return value of the function returns the `.` character if an extension is present.

If the pathname is either `.` or `..`, or the pathname does not contain the `.` character, then empty path is returned.

Additional behavior may be defined by the implementations for file systems which append additional elements (such as alternate data streams or partitioned dataset names) to extensions.

### [edit] Parameters

(none)

### [edit] Return value

The extension of the current pathname or an empty path if there's no extension.

### [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/bar.txt/bar.cc").extension() << '\n';
        std::cout << std::fs::path("/foo/bar.txt/bar.").extension() << '\n';
        std::cout << std::fs::path("/foo/bar.txt/bar").extension() << '\n';
        std::cout << std::fs::path("/foo/.").extension() << '\n';
        std::cout << std::fs::path("/foo/..").extension() << '\n';
        std::cout << std::fs::path("/foo/.hidden").extension() << '\n';
    }

Output:

    .txt
    .

    .cc
    .

    .hidden

### [edit] See also

filename | returns the filename 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/extension&oldid=68597"