##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Filesystem library

From cppreference.com
< cpp

The Filesystem library provides facilities for performing operations on file systems and their components, such as paths, regular files, and directories.

The filesystem library was originally developed as boost.filesystem, was published as the technical specification ISO/IEC TS 18822:2015, and finally merged to ISO C++ as of C++17. The boost implementation is currently available on more compilers and platforms than the C++17 library.

The filesystem library facilities may be unavailable if a hierarchical file system is not accessible to the implementation, or if it does not provide the necessary capabilities. Some features may not be available if they are not supported by the underlying file system (e.g. FAT filesystem has no hardlinks, softlinks, and other features).

The behavior is undefined if the calls to functions in this library introduce a file system race, that is, when multiple threads, processes, or computers interleave access and modification to the same object in a file system.

#### [edit] Library-wide concepts

- file: a file system object that holds data, can be written to, read from, or both. Files have names, attributes, one of which is file type:

  - directory: a file that acts as a container of directory entries, which identify other files (some of which may be other, nested, directories). When discussing a particular file, the directory in which it appears as an entry is its parent directory. The parent directory can be represented by the relative pathname "..".
  - hard link: a directory entry that associates a name with an existing file. If multiple hard links are supported, the file is removed after the last hard link to it is removed.
  - symbolic link: a directory entry that associates a name with a path, which may or may not exist.
  - regular file: a file that is not one of the other file types.

- file name: a string of characters that names a file. Permissible characters, case sensitivity, maximum length, and the disallowed names are implementation-defined. Names "." (dot) and ".." (dot-dot) have special meaning at library level.
- path: sequence of elements that identifies a file. It begins with an optional root-name (e.g. "C:" or "//server" on Windows), followed by an optional root-directory (e.g. "/" on Unix), followed by a sequence of zero or more file names (all but last of which have to be directories or links to directories). The native format (e.g. which characters are used as separators) and character encoding of the string representation of a path (the pathname) is implementation-defined, this library provides portable representation of paths.

  - absolute path: a path that unambiguously identifies the location of a file.
  - canonical path: an absolute path that includes no symlinks, "." or ".." elements.
  - relative path: a path that identifies the location of a file relative to some location on the file system. The special path names "." (dot, "current directory") and ".." (dot-dot, "parent directory") are relative paths.

### [edit] Classes

Defined in header `<filesystem>`
Defined in namespace `filesystem`
path (C++17) | represents a path (class) [edit]
filesystem_error (C++17) | an exception thrown on file system errors (class) [edit]
directory_entry (C++17) | a directory entry (class) [edit]
directory_iterator (C++17) | an iterator to the contents of the directory (class) [edit]
recursive_directory_iterator (C++17) | an iterator to the contents of a directory and its subdirectories (class) [edit]
file_status (C++17) | represents file type and permissions (class) [edit]
space_info (C++17) | information about free and available space on the filesystem (class) [edit]
file_type (C++17) | the type of a file (enum) [edit]
perms (C++17) | identifies file system permissions (enum) [edit]
copy_options (C++17) | specifies semantics of copy operations (enum) [edit]
directory_options (C++17) | options for iterating directory contents (enum) [edit]
file_time_type (C++17) | represents file time values (typedef) [edit]

### [edit] Non-member functions

absolute system_complete (C++17)(C++17) | composes an absolute path converts a path to an absolute path replicating OS-specific behavior (function) [edit]
canonical weakly_canonical (C++17) | composes a canonical path (function) [edit]
relative proximate (C++17) | composes a relative path (function) [edit]
copy (C++17) | copies files or directories (function) [edit]
copy_file (C++17) | copies file contents (function) [edit]
copy_symlink (C++17) | copies a symbolic link (function) [edit]
create_directory create_directories (C++17)(C++17) | creates new directory (function) [edit]
create_hard_link (C++17) | creates a hard link (function) [edit]
create_symlink create_directory_symlink (C++17)(C++17) | creates a symbolic link (function) [edit]
current_path (C++17) | return current working directory (function) [edit]
exists (C++17) | checks whether path refers to existing file system object (function) [edit]
equivalent (C++17) | checks whether two paths refer to the same file system object (function) [edit]
file_size (C++17) | returns the size of a file (function) [edit]
hard_link_count (C++17) | returns the number of hard links referring to the specific file (function) [edit]
last_write_time (C++17) | gets or sets the time of the last data modification (function) [edit]
permissions (C++17) | modifies file access permissions (function) [edit]
read_symlink (C++17) | obtains the target of a symbolic link (function) [edit]
remove remove_all (C++17)(C++17) | removes a file or empty directory removes a file or directory and all its contents, recursively (function) [edit]
rename (C++17) | moves or renames a file or directory (function) [edit]
resize_file (C++17) | changes the size of a regular file by truncation or zero-fill (function) [edit]
space (C++17) | determines available free space on the file system (function) [edit]
status symlink_status (C++17)(C++17) | determines file attributes determines file attributes, checking the symlink target (function) [edit]
temp_directory_path (C++17) | returns a directory suitable for temporary files (function) [edit]
##### File types
is_block_file (C++17) | checks whether the given path refers to block device (function) [edit]
is_character_file (C++17) | checks whether the given path refers to a character device (function) [edit]
is_directory (C++17) | checks whether the given path refers to a directory (function) [edit]
is_empty (C++17) | checks whether the given path refers to an empty file or directory (function) [edit]
is_fifo (C++17) | checks whether the given path refers to a named pipe (function) [edit]
is_other (C++17) | checks whether the argument refers to an other file (function) [edit]
is_regular_file (C++17) | checks whether the argument refers to a regular file (function) [edit]
is_socket (C++17) | checks whether the argument refers to a named IPC socket (function) [edit]
is_symlink (C++17) | checks whether the argument refers to a symbolic link (function) [edit]
status_known (C++17) | checks whether file status is known (function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/filesystem&oldid=90174"