How similar are Boost.Filesystem and the C++ standard filesystem library?
There are a number of differences. Some were, I believe, Boost changes that were never propagated. For example, there is no path.filename_is_dot()
query (as discussed below, it would be less useful in std::filesystem
anyway).
There was also a good bit of late-breaking news on this front:
- Support for non-POSIX-like filesystems:
- Specify whether a string is OS-native or POSIX-like (or let the implementation decide, which is (still) the default)
- An implementation may define additional file types (beyond regular, directory, socket, etc.)
- An implementation may define
file_size
for a directory or device file
filename()
, normalization, and relative/absolute conversions redefined (examples for POSIX):path("foo/.").lexically_normal()=="foo/"
(is the opposite in Boost)path("foo/").filename()==""
(ispath(".")
in Boost)remove_filename()
leaves the trailing slash and is thus idempotent (it assignsparent_path()
in Boost)path(".profile").extension()==""
(is the whole name in Boost)path
decompositions and combinations can preserve things like alternate data stream names that are normally invisiblepath("foo")/"/bar"=="/bar"
(ispath("foo/bar")
in Boost), which allows composing relative file names with others (absolute or relative) and replaces Boost'sabsolute()
- Boost's
system_complete()
(which takes only one argument) is renamed toabsolute()
canonical()
thus takes only one argument (fixed in a DR)lexically_relative()
handles..
and root elements correctlypermissions()
takes more arguments (Boost combines them into a bitmask)
Note that Boost.Filesystem v4 is under development and is supposed to be C++17-compatible (but therefore incompatible in many respects with v3).
Differences between c++14 std::experimental::filesystem::v1 and c++17 std::filesystem?
The major papers making changes to the filesystem library are
- P0219R1, adding relative paths support
- P0317R1, adding caching to
directory_entry
- P0492R2, a lengthy list of fixes and changes in response to national body comments
- P0430R2, support for certain non-POSIX systems
There are also some relatively minor fixes and changes that can be found in the LWG issue list. Look for issues with "C++17" status. Note that some of these changes are then superseded by the papers listed above.
For existing Filesystem TS code, I expect that P0492R2 is the one that matters the most, since the remaining papers are mostly feature additions rather than changes. P0492R2 includes both technical clarifications and significant semantic changes. Some in the latter category that immediately come to mind are:
path(".profile").stem()
is now".profile"
operator/
onpath
had its semantics changed significantly if the rhs is an absolute path or has a root-name.path("/foo") / "/bar"
is now"/bar"
rather than"/foo/bar"
;path("C:\\x") / "D:y"
on Windows is now"D:y"
.- The old
absolute
is gone.system_complete
has been renamedabsolute
. permissions
's signature got a minor change.
What is the best way of determining that two file paths are referring to the same file object?
You could check out the Boost.Filesystem
library. Specifically, there is a method equivalent
that seems to do exactly what you are looking for:
using namespace boost::filesystem;
path p("/path/to/file/one");
path q("/sym_link/to/one");
assert(equivalent(p, q));
c++ Boost if .extension() == this would mean this file is a folder?
Files can exist without any extension, so this won't work.
Have a look at boost::filesystem::is_directory
.
By the way, Boost.Filesystem library was merged into C++17 standard. So, if your compiler supports C++17, consider using the standard library for filesystem operations.
How can I know the type of a file using Boost.Filesystem?
How about:
http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/index.htm
The functions for figuring out the file type (directory, normal file etc.) is found on this subpage: http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/reference.html#file_status
If you are looking for the file extension check out: template <class Path> typename Path::string_type extension(const Path &p);
on the page:
http://www.boost.org/doc/libs/1_39_0/libs/filesystem/doc/reference.html#Convenience-functions
Related Topics
What Is the Comdat Section Used For
Printing Double Without Losing Precision
C++11 Anonymous Union with Non-Trivial Members
Efficiently Reading a Very Large Text File in C++
Std::Lexical_Cast - Is There Such a Thing
How to Pass Derived Classes by Reference to a Function Taking Base Class as a Parameter
Pros & Cons of Putting All Code in Header Files in C++
Why Does This Simple Std::Thread Example Not Work
Reading an Application's Manifest File
Replace Multiple Spaces with One Space in a String
Why Is Operator!= Removed in C++20 for Many Standard Library Types
Cannot Create Constexpr Std::Vector
What Is the Ndebug Preprocessor MACro Used for (On Different Platforms)
Why Does Valgrind Say Basic Sdl Program Is Leaking Memory
Handling Overflow When Casting Doubles to Integers in C
How to Avoid Entering Library's Source Files While Debugging in Qt Creator with Gdb