Filesystem
Version 4 |
Home Tutorial Reference FAQ Releases Portability V4 V3 Intro V3 Design Deprecated Bug Reports |
Version 4 is a significant revision of the Boost Filesystem library that makes its interface and behavior closer to std::filesystem that was introduced in C++17 and updated in the later standards. It removes the features that were deprecated in Version 3 and makes a number of breaking changes.
Users can select Boost.Filesystem v4 version by defining BOOST_FILESYSTEM_VERSION
macro to 4 when compiling their code. There is no need to separately compile Boost.Filesystem for each library version — a single binary supports both v3 and v4. Users should avoid using both v3 and v4 in the same application as this can lead to subtle bugs.
path::filename
no longer returns root name or root directory if the path contains no
other elements. For example, on Windows path("C:").filename()
used to return "C:" and path("C:\").filename()
used to return "\" and both will return an empty path now. This also affects path::stem
and path::extension
methods, as those are based on path::filename
.path::stem
and path::extension
no longer treat a filename that starts with a dot and has no other dots as an extension. Filenames starting with a dot are commonly treated as filenames with an empty extension. The leading dot is used to indicate a hidden file on most UNIX-like systems.path::filename
and path::iterator
no longer return an implicit trailing dot (".") element if the path ends with a directory separator. Instead, an empty path is returned, similar to C++17 std::filesystem. This also affects other methods that are defined in terms of iterators or filename, such as path::stem
, path::compare
or lexicographical_compare
. For example, path("a/b/") == path("a/b/.")
no longer holds true.path::lexically_normal
no longer produces a trailing dot (".") element and omits a directory separator after a trailing dot-dot ("..") element in the normalized paths.path
appends consider root name and root directory of the appended path. If the appended path is absolute, or root name is present and differs from the source path, the resulting path is equivalent to the appended path. If root directory is present, the result is the root directory and relative path rebased on top of the root name of the source path. Otherwise, the behavior is similar to v3. This behavior is similar to C++17 std::filesystem.path
no longer supports construction, assignment or appending from containers of characters. Use string types or iterators as the source for these opereations instead.path::remove_filename
preserves the trailing directory separator, so that path::has_filename
returns false
after a successful call to path::remove_filename
.directory_entry
constructors and modifiers that initialize or modify path of the directory entry automatically call directory_entry::refresh
instead of clearing cached file statuses. This means that the file identified by the new path needs to be accessible in the filesystem at the point of the call.directory_entry
constructors and modifiers that accept file_status
arguments to initialize cached file statuses are removed. The amount of cached data
is an implementation detail of directory_entry
, and in the future it may not be limited to just file statuses. Users should rely on automatic refreshes of the cached data.© Copyright Andrey Semashev, 2021-2023
Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt