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.

Contents

[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

#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

returns the filename path component
(public member function)
returns the stem path component
(public member function)