Non-member functions
Apart from the classes, C++ has pre-defined functions to help us fully use filesystem library.
We'll cover the following
Many non-member functions exist for manipulating the filesystem, which are:
Non-member functions | Description |
---|---|
absolute |
Composes an absolute path. |
canonical and weakly_canonical |
Composes a canonical path. |
relative and proximate |
Composes a relative path. |
copy |
Copies files or directories. |
copy_file |
Copies file contents. |
copy_symlink |
Copies a symbolic link. |
create_directory and create_directories |
Creates a new directory. |
create_hard_link |
Creates a hard link. |
create_symlink and create_directory_symlink |
Creates a symbolic link. |
current_path |
Returns the current working directory. |
exists |
Checks if path refers to an existing file. |
equivalent |
Checks if two paths refer to the same file. |
file_size |
Returns the size of the file. |
hard_link_count |
Returns the number of hard links to a file. |
last_write_time |
Gets and sets the time of the last file modification. |
permissions |
Modifies the file access permissions. |
read_symlink |
Gets the target of the symbolic link. |
remove |
Removes a file or an empty directory. |
remove_all |
Removes a file or a directory with all its content recursively. |
rename |
Moves or renames a file or directory. |
resize_file |
Changes the size of a file by truncation. |
space |
Returns the free space on the filesystem. |
status |
Determines the file attributes. |
symlink_status |
Determines the file attributes and checks the symlink target. |
temp_directory_path |
Returns a directory for temporary files. |
Read and set the last write time of a file
Thanks to the global function std::filesystem::last_write_time
, you can read and set the last write time of a file. Here is an example, based on the last_write_time
example from en.cppreference.com.
Get hands-on with 1200+ tech skills courses.