Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

<filesystem> (v3)

 

Include the header <filesystem> for access to classes and functions that manipulate and retrieve information about paths, files and directories.

#include <filesystem>
using namespace std::tr2::sys;
System_CAPS_importantImportant

As of C++ 14, the <filesystem> header is not yet a C++ standard, although it is expected to be standardized in approximately its current form in the C++ 17 time frame.


This header supports filesystems for one of two broad classes of host operating systems: Microsoft Windows and Posix.

While most functionality is common to both operating systems, this document identifies where differences occur. For example:

  • Windows supports multiple root names, such as c: or \\network_name. So a filesystem consists of a forest of trees, each with its own root directory, such as c:\ or \\network_name\, and each with its own current directory, for completing a relative pathname (one that is not an absolute pathname).

  • Posix supports a single tree, with no root name, the single root directory /, and a single current directory.

Another significant difference is the native representation of pathnames:

  • Windows uses a nul-terminated sequence of wchar_t, encoded as UTF-16 (one or two elements for each character).

  • Posix uses a nul-terminated sequence of char, encoded as UTF-8 (one or more elements for each character).

  • An object of class path stores the pathname in native form, but supports easy conversion between this stored form and several external forms:

    • A nul-terminated sequence of char, encoded as favored by the operating system.

    • A nul-terminated sequence of char, encoded as UTF-8.

    • A nul-terminated sequence of wchar_t, encoded as favored by the operating system.

    • A nul-terminated sequence of char16_t, encoded as UTF-16.

    • A nul-terminated sequence of char32_t, encoded as UTF-32.

Interconversions between these representations are mediated, as needed, by the use of one or more codecvt facets. If a specific locale object is not designated, these facets are obtained from the global locale.

Another difference is the detail with which each operating system lets you specify file or directory access permissions:

  1. Windows records whether a file is read only or writable, an attribute that has no meaning for directories.

  2. Posix records whether a file can be read, written, or executed (scanned if a directory), by the owner, by the owner's group, or by everybody, plus a few other permissions.

Common to both systems is the structure imposed on a pathname once you get past the root name. For the pathname c:/abc/xyz/def.ext:

  • The root name is c:.

  • The root directory is /.

  • The root path is c:/.

  • The relative path is abc/xyz/def.ext.

  • The parent path is c:/abc/xyz.

  • The filename is def.ext.

  • The stem is def.

  • The extension is .ext.

A minor difference is the preferred separator, between the sequence of directories in a pathname. Both operating systems let you write a forward slash /, but in some contexts Windows prefers a backslash \.

Finally, an important feature of path objects is that you can use them wherever an argument called filename is required in the classes defined in the header <fstream>.

For more information and code examples, see File System Navigation.

Name

Description

directory_entry Class

Describes an object that is returned by a directory_iterator or a recursive_directory_iterator and contains information about a

directory_iterator Class

Describes an input iterator that sequences through the file names in a file-system directory.

filesystem_error Class

A base class for exceptions that are thrown to report a low-level system overflow.

path Class

Defines a class that stores an object of template type String that is suitable for use as a file name.

recursive_directory_iterator Class

Describes an input iterator that sequences through the file names in a file-system directory. The iterator can also descend into subdirectories.

file_status Class

Wraps a file_type.

Name

Description

space_info Structure

Holds information about a volume.

Name

Description

copy_option Enumeration <filesystem>

An enumeration that is used with copy_file and determines behavior if a destination file already exists.

directory_options Enumeration

An enumeration that specifies options for directory iterators.

file_type Enumeration 

An enumeration for file types.

perms Enumeration

A bitmask type used to convey permissions and options to permissions

Show:
© 2016 Microsoft