This header is part of the
library.
Includes
(C++20)
support
Classes
Defined in namespace std::filesystem
(C++17)
represents a path
(class)
(C++17)
an exception thrown on file system errors
(class)
(C++17)
a directory entry
(class)
(C++17)
an iterator to the contents of the directory
(class)
(C++17)
an iterator to the contents of a directory and its subdirectories
(class)
(C++17)
represents file type and permissions
(class)
(C++17)
information about free and available space on the filesystem
(class)
(C++17)
the type of a file
(enum)
(C++17)
identifies file system permissions
(enum)
(C++17)
specifies semantics of permissions operations
(enum)
(C++17)
specifies semantics of copy operations
(enum)
(C++17)
options for iterating directory contents
(enum)
(C++17)
represents file time values
(typedef)
Defined in namespace std
std::hash<std::filesystem::path>
(C++17)
hash support for
(class template specialization)
Forward declarations Defined in header
Defined in namespace std
(C++11)
hash function object
(class template)
Functions
Defined in namespace std::filesystem
(C++17)(deprecated in C++20)
creates a path from a UTF-8 encoded source
(function)
(C++17)
composes an absolute path
(function)
(C++17)
composes a canonical path
(function)
(C++17)
composes a relative path
(function)
(C++17)
copies files or directories
(function)
(C++17)
copies file contents
(function)
(C++17)
copies a symbolic link
(function)
create_directorycreate_directories
(C++17)(C++17)
creates new directory
(function)
(C++17)
creates a hard link
(function)
create_symlinkcreate_directory_symlink
(C++17)(C++17)
creates a symbolic link
(function)
(C++17)
returns or sets the current working directory
(function)
(C++17)
checks whether path refers to existing file system object
(function)
(C++17)
checks whether two paths refer to the same file system object
(function)
(C++17)
returns the size of a file
(function)
(C++17)
returns the number of hard links referring to the specific file
(function)
(C++17)
gets or sets the time of the last data modification
(function)
(C++17)
modifies file access permissions
(function)
(C++17)
obtains the target of a symbolic link
(function)
(C++17)(C++17)
removes a file or empty directory
removes a file or directory and all its contents, recursively
(function)
(C++17)
moves or renames a file or directory
(function)
(C++17)
changes the size of a regular file by truncation or zero-fill
(function)
(C++17)
determines available free space on the file system
(function)
(C++17)(C++17)
determines file attributes
determines file attributes, checking the symlink target
(function)
(C++17)
returns a directory suitable for temporary files
(function)
File types
(C++17)
checks whether the given path refers to block device
(function)
(C++17)
checks whether the given path refers to a character device
(function)
(C++17)
checks whether the given path refers to a directory
(function)
(C++17)
checks whether the given path refers to an empty file or directory
(function)
(C++17)
checks whether the given path refers to a named pipe
(function)
(C++17)
checks whether the argument refers to an other file
(function)
(C++17)
checks whether the argument refers to a regular file
(function)
(C++17)
checks whether the argument refers to a named IPC socket
(function)
(C++17)
checks whether the argument refers to a symbolic link
(function)
(C++17)
checks whether file status is known
(function)
Synopsis
#include<compare>namespacestd::filesystem{// pathsclasspath;// path non-member functionsvoidswap(path&lhs,path&rhs)noexcept;size_thash_value(constpath&p)noexcept;// filesystem errorsclassfilesystem_error;// directory entriesclassdirectory_entry;// directory iteratorsclassdirectory_iterator;// range access for directory iteratorsdirectory_iteratorbegin(directory_iteratoriter)noexcept;directory_iteratorend(directory_iterator)noexcept;// recursive directory iteratorsclassrecursive_directory_iterator;// range access for recursive directory iteratorsrecursive_directory_iteratorbegin(recursive_directory_iteratoriter)noexcept;recursive_directory_iteratorend(recursive_directory_iterator)noexcept;// file statusclassfile_status;structspace_info{uintmax_tcapacity;uintmax_tfree;uintmax_tavailable;friendbooloperator==(constspace_info&,constspace_info&)=default;};// enumerationsenumclassfile_type;enumclassperms;enumclassperm_options;enumclasscopy_options;enumclassdirectory_options;usingfile_time_type=chrono::time_point<chrono::file_clock>;// filesystem operationspathabsolute(constpath&p);pathabsolute(constpath&p,error_code&ec);pathcanonical(constpath&p);pathcanonical(constpath&p,error_code&ec);voidcopy(constpath&from,constpath&to);voidcopy(constpath&from,constpath&to,error_code&ec);voidcopy(constpath&from,constpath&to,copy_optionsoptions);voidcopy(constpath&from,constpath&to,copy_optionsoptions,error_code&ec);boolcopy_file(constpath&from,constpath&to);boolcopy_file(constpath&from,constpath&to,error_code&ec);boolcopy_file(constpath&from,constpath&to,copy_optionsoption);boolcopy_file(constpath&from,constpath&to,copy_optionsoption,error_code&ec);voidcopy_symlink(constpath&existing_symlink,constpath&new_symlink);voidcopy_symlink(constpath&existing_symlink,constpath&new_symlink,error_code&ec)noexcept;boolcreate_directories(constpath&p);boolcreate_directories(constpath&p,error_code&ec);boolcreate_directory(constpath&p);boolcreate_directory(constpath&p,error_code&ec)noexcept;boolcreate_directory(constpath&p,constpath&attributes);boolcreate_directory(constpath&p,constpath&attributes,error_code&ec)noexcept;voidcreate_directory_symlink(constpath&to,constpath&new_symlink);voidcreate_directory_symlink(constpath&to,constpath&new_symlink,error_code&ec)noexcept;voidcreate_hard_link(constpath&to,constpath&new_hard_link);voidcreate_hard_link(constpath&to,constpath&new_hard_link,error_code&ec)noexcept;voidcreate_symlink(constpath&to,constpath&new_symlink);voidcreate_symlink(constpath&to,constpath&new_symlink,error_code&ec)noexcept;pathcurrent_path();pathcurrent_path(error_code&ec);voidcurrent_path(constpath&p);voidcurrent_path(constpath&p,error_code&ec)noexcept;boolequivalent(constpath&p1,constpath&p2);boolequivalent(constpath&p1,constpath&p2,error_code&ec)noexcept;boolexists(file_statuss)noexcept;boolexists(constpath&p);boolexists(constpath&p,error_code&ec)noexcept;uintmax_tfile_size(constpath&p);uintmax_tfile_size(constpath&p,error_code&ec)noexcept;uintmax_thard_link_count(constpath&p);uintmax_thard_link_count(constpath&p,error_code&ec)noexcept;boolis_block_file(file_statuss)noexcept;boolis_block_file(constpath&p);boolis_block_file(constpath&p,error_code&ec)noexcept;boolis_character_file(file_statuss)noexcept;boolis_character_file(constpath&p);boolis_character_file(constpath&p,error_code&ec)noexcept;boolis_directory(file_statuss)noexcept;boolis_directory(constpath&p);boolis_directory(constpath&p,error_code&ec)noexcept;boolis_empty(constpath&p);boolis_empty(constpath&p,error_code&ec);boolis_fifo(file_statuss)noexcept;boolis_fifo(constpath&p);boolis_fifo(constpath&p,error_code&ec)noexcept;boolis_other(file_statuss)noexcept;boolis_other(constpath&p);boolis_other(constpath&p,error_code&ec)noexcept;boolis_regular_file(file_statuss)noexcept;boolis_regular_file(constpath&p);boolis_regular_file(constpath&p,error_code&ec)noexcept;boolis_socket(file_statuss)noexcept;boolis_socket(constpath&p);boolis_socket(constpath&p,error_code&ec)noexcept;boolis_symlink(file_statuss)noexcept;boolis_symlink(constpath&p);boolis_symlink(constpath&p,error_code&ec)noexcept;file_time_typelast_write_time(constpath&p);file_time_typelast_write_time(constpath&p,error_code&ec)noexcept;voidlast_write_time(constpath&p,file_time_typenew_time);voidlast_write_time(constpath&p,file_time_typenew_time,error_code&ec)noexcept;voidpermissions(constpath&p,permsprms,perm_optionsopts=perm_options::replace);voidpermissions(constpath&p,permsprms,error_code&ec)noexcept;voidpermissions(constpath&p,permsprms,perm_optionsopts,error_code&ec);pathproximate(constpath&p,error_code&ec);pathproximate(constpath&p,constpath&base=current_path());pathproximate(constpath&p,constpath&base,error_code&ec);pathread_symlink(constpath&p);pathread_symlink(constpath&p,error_code&ec);pathrelative(constpath&p,error_code&ec);pathrelative(constpath&p,constpath&base=current_path());pathrelative(constpath&p,constpath&base,error_code&ec);boolremove(constpath&p);boolremove(constpath&p,error_code&ec)noexcept;uintmax_tremove_all(constpath&p);uintmax_tremove_all(constpath&p,error_code&ec);voidrename(constpath&from,constpath&to);voidrename(constpath&from,constpath&to,error_code&ec)noexcept;voidresize_file(constpath&p,uintmax_tsize);voidresize_file(constpath&p,uintmax_tsize,error_code&ec)noexcept;space_infospace(constpath&p);space_infospace(constpath&p,error_code&ec)noexcept;file_statusstatus(constpath&p);file_statusstatus(constpath&p,error_code&ec)noexcept;boolstatus_known(file_statuss)noexcept;file_statussymlink_status(constpath&p);file_statussymlink_status(constpath&p,error_code&ec)noexcept;pathtemp_directory_path();pathtemp_directory_path(error_code&ec);pathweakly_canonical(constpath&p);pathweakly_canonical(constpath&p,error_code&ec);}// hash supportnamespacestd{template<classT>structhash;template<>structhash<filesystem::path>;}namespacestd::ranges{template<>inlineconstexprboolenable_borrowed_range<filesystem::directory_iterator>=true;template<>inlineconstexprboolenable_borrowed_range<filesystem::recursive_directory_iterator>=true;template<>inlineconstexprboolenable_view<filesystem::directory_iterator>=true;template<>inlineconstexprboolenable_view<filesystem::recursive_directory_iterator>=true;}Class
namespacestd::filesystem{classpath{public:usingvalue_type=/* see description */;usingstring_type=basic_string<value_type>;staticconstexprvalue_typepreferred_separator=/* see description */;// enumeration formatenumformat;// constructors and destructorpath()noexcept;path(constpath&p);path(path&&p)noexcept;path(string_type&&source,formatfmt=auto_format);template<classSource>path(constSource&source,formatfmt=auto_format);template<classInputIt>path(InputItfirst,InputItlast,formatfmt=auto_format);template<classSource>path(constSource&source,constlocale&loc,formatfmt=auto_format);template<classInputIt>path(InputItfirst,InputItlast,constlocale&loc,formatfmt=auto_format);~path();// assignmentspath&operator=(constpath&p);path&operator=(path&&p)noexcept;path&operator=(string_type&&source);path&assign(string_type&&source);template<classSource>path&operator=(constSource&source);template<classSource>path&assign(constSource&source);template<classInputIt>path&assign(InputItfirst,InputItlast);// appendspath&operator/=(constpath&p);template<classSource>path&operator/=(constSource&source);template<classSource>path&append(constSource&source);template<classInputIt>path&append(InputItfirst,InputItlast);// concatenationpath&operator+=(constpath&x);path&operator+=(conststring_type&x);path&operator+=(basic_string_view<value_type>x);path&operator+=(constvalue_type*x);path&operator+=(value_typex);template<classSource>path&operator+=(constSource&x);template<classECharT>path&operator+=(ECharTx);template<classSource>path&concat(constSource&x);template<classInputIt>path&concat(InputItfirst,InputItlast);// modifiersvoidclear()noexcept;path&make_preferred();path&remove_filename();path&replace_filename(constpath&replacement);path&replace_extension(constpath&replacement=path());voidswap(path&rhs)noexcept;// non-member operatorsfriendbooloperator==(constpath&lhs,constpath&rhs)noexcept;friendstrong_orderingoperator<=>(constpath&lhs,constpath&rhs)noexcept;friendpathoperator/(constpath&lhs,constpath&rhs);// native format observersconststring_type&native()constnoexcept;constvalue_type*c_str()constnoexcept;operatorstring_type()const;template<classECharT,classTraits=char_traits<ECharT>,classAllocator=allocator<ECharT>>basic_string<ECharT,Traits,Allocator>string(constAllocator&a=Allocator())const;std::stringstring()const;std::wstringwstring()const;std::u8stringu8string()const;std::u16stringu16string()const;std::u32stringu32string()const;// generic format observerstemplate<classECharT,classTraits=char_traits<ECharT>,classAllocator=allocator<ECharT>>basic_string<ECharT,Traits,Allocator>generic_string(constAllocator&a=Allocator())const;std::stringgeneric_string()const;std::wstringgeneric_wstring()const;std::u8stringgeneric_u8string()const;std::u16stringgeneric_u16string()const;std::u32stringgeneric_u32string()const;// compareintcompare(constpath&p)constnoexcept;intcompare(conststring_type&s)const;intcompare(basic_string_view<value_type>s)const;intcompare(constvalue_type*s)const;// decompositionpathroot_name()const;pathroot_directory()const;pathroot_path()const;pathrelative_path()const;pathparent_path()const;pathfilename()const;pathstem()const;pathextension()const;// queryboolempty()constnoexcept;boolhas_root_name()const;boolhas_root_directory()const;boolhas_root_path()const;boolhas_relative_path()const;boolhas_parent_path()const;boolhas_filename()const;boolhas_stem()const;boolhas_extension()const;boolis_absolute()const;boolis_relative()const;// generationpathlexically_normal()const;pathlexically_relative(constpath&base)const;pathlexically_proximate(constpath&base)const;// iteratorsclassiterator;usingconst_iterator=iterator;iteratorbegin()const;iteratorend()const;// path inserter and extractortemplate<classCharT,classTraits>friendbasic_ostream<CharT,Traits>&operator<<(basic_ostream<CharT,Traits>&os,constpath&p);template<classCharT,classTraits>friendbasic_istream<CharT,Traits>&operator>>(basic_istream<CharT,Traits>&is,path&p);};}Class
std::filesystem::filesystem_error
namespacestd::filesystem{classfilesystem_error:publicsystem_error{public:filesystem_error(conststring&what_arg,error_codeec);filesystem_error(conststring&what_arg,constpath&p1,error_codeec);filesystem_error(conststring&what_arg,constpath&p1,constpath&p2,error_codeec);constpath&path1()constnoexcept;constpath&path2()constnoexcept;constchar*what()constnoexceptoverride;};}Class
std::filesystem::directory_entry
namespacestd::filesystem{classdirectory_entry{public:// constructors and destructordirectory_entry()noexcept=default;directory_entry(constdirectory_entry&)=default;directory_entry(directory_entry&&)noexcept=default;explicitdirectory_entry(constfilesystem::path&p);directory_entry(constfilesystem::path&p,error_code&ec);~directory_entry();// assignmentsdirectory_entry&operator=(constdirectory_entry&)=default;directory_entry&operator=(directory_entry&&)noexcept=default;// modifiersvoidassign(constfilesystem::path&p);voidassign(constfilesystem::path&p,error_code&ec);voidreplace_filename(constfilesystem::path&p);voidreplace_filename(constfilesystem::path&p,error_code&ec);voidrefresh();voidrefresh(error_code&ec)noexcept;// observersconstfilesystem::path&path()constnoexcept;operatorconstfilesystem::path&()constnoexcept;boolexists()const;boolexists(error_code&ec)constnoexcept;boolis_block_file()const;boolis_block_file(error_code&ec)constnoexcept;boolis_character_file()const;boolis_character_file(error_code&ec)constnoexcept;boolis_directory()const;boolis_directory(error_code&ec)constnoexcept;boolis_fifo()const;boolis_fifo(error_code&ec)constnoexcept;boolis_other()const;boolis_other(error_code&ec)constnoexcept;boolis_regular_file()const;boolis_regular_file(error_code&ec)constnoexcept;boolis_socket()const;boolis_socket(error_code&ec)constnoexcept;boolis_symlink()const;boolis_symlink(error_code&ec)constnoexcept;uintmax_tfile_size()const;uintmax_tfile_size(error_code&ec)constnoexcept;uintmax_thard_link_count()const;uintmax_thard_link_count(error_code&ec)constnoexcept;file_time_typelast_write_time()const;file_time_typelast_write_time(error_code&ec)constnoexcept;file_statusstatus()const;file_statusstatus(error_code&ec)constnoexcept;file_statussymlink_status()const;file_statussymlink_status(error_code&ec)constnoexcept;booloperator==(constdirectory_entry&rhs)constnoexcept;strong_orderingoperator<=>(constdirectory_entry&rhs)constnoexcept;// insertertemplate<classCharT,classTraits>friendbasic_ostream<CharT,Traits>&operator<<(basic_ostream<CharT,Traits>&os,constdirectory_entry&d);private:filesystem::pathpathobject;// exposition onlyfriendclassdirectory_iterator;// exposition only};}Class
std::filesystem::directory_iterator
namespacestd::filesystem{classdirectory_iterator{public:usingiterator_category=input_iterator_tag;usingvalue_type=directory_entry;usingdifference_type=ptrdiff_t;usingpointer=constdirectory_entry*;usingreference=constdirectory_entry&;// member functionsdirectory_iterator()noexcept;explicitdirectory_iterator(constpath&p);directory_iterator(constpath&p,directory_optionsoptions);directory_iterator(constpath&p,error_code&ec);directory_iterator(constpath&p,directory_optionsoptions,error_code&ec);directory_iterator(constdirectory_iterator&rhs);directory_iterator(directory_iterator&&rhs)noexcept;~directory_iterator();directory_iterator&operator=(constdirectory_iterator&rhs);directory_iterator&operator=(directory_iterator&&rhs)noexcept;constdirectory_entry&operator*()const;constdirectory_entry*operator->()const;directory_iterator&operator++();directory_iterator&increment(error_code&ec);booloperator==(default_sentinel_t)constnoexcept{return*this==directory_iterator();}// other members as required by input iterators};}Class
std::filesystem::recursive_directory_iterator
namespacestd::filesystem{classrecursive_directory_iterator{public:usingiterator_category=input_iterator_tag;usingvalue_type=directory_entry;usingdifference_type=ptrdiff_t;usingpointer=constdirectory_entry*;usingreference=constdirectory_entry&;// constructors and destructorrecursive_directory_iterator()noexcept;explicitrecursive_directory_iterator(constpath&p);recursive_directory_iterator(constpath&p,directory_optionsoptions);recursive_directory_iterator(constpath&p,directory_optionsoptions,error_code&ec);recursive_directory_iterator(constpath&p,error_code&ec);recursive_directory_iterator(constrecursive_directory_iterator&rhs);recursive_directory_iterator(recursive_directory_iterator&&rhs)noexcept;~recursive_directory_iterator();// observersdirectory_optionsoptions()const;intdepth()const;boolrecursion_pending()const;constdirectory_entry&operator*()const;constdirectory_entry*operator->()const;// modifiersrecursive_directory_iterator&operator=(constrecursive_directory_iterator&rhs);recursive_directory_iterator&operator=(recursive_directory_iterator&&rhs)noexcept;recursive_directory_iterator&operator++();recursive_directory_iterator&increment(error_code&ec);voidpop();voidpop(error_code&ec);voiddisable_recursion_pending();booloperator==(default_sentinel_t)constnoexcept{return*this==recursive_directory_iterator();}// other members as required by input iterators};}Class
namespacestd::filesystem{classfile_status{public:// constructors and destructorfile_status()noexcept:file_status(file_type::none){}explicitfile_status(file_typeft,permsprms=perms::unknown)noexcept;file_status(constfile_status&)noexcept=default;file_status(file_status&&)noexcept=default;~file_status();// assignmentsfile_status&operator=(constfile_status&)noexcept=default;file_status&operator=(file_status&&)noexcept=default;// modifiersvoidtype(file_typeft)noexcept;voidpermissions(permsprms)noexcept;// observersfile_typetype()constnoexcept;permspermissions()constnoexcept;friendbooloperator==(constfile_status&lhs,constfile_status&rhs)noexcept{returnlhs.type()==rhs.type()&&lhs.permissions()==rhs.permissions();}};}