The Boost.Filesystem library provides facilities to manipulate files and directories, and the paths that identify them.
Questions tagged [boost-filesystem]
353 questions
18
votes
2 answers
Why does boost::filesystem::canonical() require the target path to exist?
The documentation for boost::filesystem::canonical(const path& p) states:
Overview: Converts p, which must exist, to an absolute path that has no symbolic link, dot, or dot-dot elements.
...
Remarks: !exists(p) is an error.
The consequence of this…

Jeremy
- 5,055
- 1
- 28
- 44
17
votes
1 answer
Why do boost::filesystem::path and std::filesystem::path lack operator+?
Consider the following assertions about path decomposition, where each local variable e.g. stem has the obvious initialization e.g. auto stem = path.stem() —
assert(root_path == root_name / root_directory);
assert(path == root_name / root_directory…

Quuxplusone
- 23,928
- 8
- 94
- 159
16
votes
1 answer
Invalid cross-device link error with boost filesystem
I am trying to move a file from a location to another using boost::filesystem.
I used boost::filesystem::rename function but when I try to do that I have the following error.
terminate called after throwing an instance of…

Abruzzo Forte e Gentile
- 14,423
- 28
- 99
- 173
16
votes
2 answers
Boost Filesystem. is_directory never works
I have been searching high and low to get this question answered, and I can't seem to debug the problem out!
So, this is what I have.
I have installed boost via homebrew (Mac OSX Mavericks) version 1.55.0.
Other boost libraries work fine, but…

taylorcressy
- 966
- 8
- 23
16
votes
1 answer
C++ Boost Filesystem: How to modify stem from a path?
I'm using the Boost Filesystem library.
I have a path
boost::filesystem::path P("/foo/bar.baz");
I want to modify the stem part of path p to "bar_quz", so path P stays
/foo/bar_quz.baz
Can someone help me?
Thanks

ireallydontknow
- 173
- 1
- 1
- 6
15
votes
0 answers
Directories created by boost::filesystem::create_directories() not immediately accessible?
I am using boost::filesystem::create_directories() to create new directories. When I try to access these directories shortly after creation, I get an error saying: no such directory. But if I sleep for a while after creating directories everything…

polapts
- 5,493
- 10
- 37
- 49
15
votes
2 answers
Get an ordered list of files in a folder
I have used boost::filesystem::directory_iterator in order to get a list of all the available files into a given folder.
The problem is that I supposed this method would give me the files in alphabetical order, while the results seem pretty…

Roman Rdgz
- 12,836
- 41
- 131
- 207
14
votes
2 answers
How to determine if a file is contained by path with Boost Filesystem Library v3?
How can I determine if file is contained by path with boost filesystem v3.
I saw that there is a lesser or greater operator but this seems to be only lexical.
The best way I saw was the following:
Take the two absolute paths of the file and the…

David Feurle
- 2,687
- 22
- 38
13
votes
4 answers
How to compare time_t and std::filesystem::file_time_type
I'm converting some code over from boost::filesystem to std::filesystem. Previous code used boost::filesystem::last_write_time() which returns a time_t so direct comparison to a time_t object I already held was trivial. By the way, this time_t I…

PeteUK
- 1,062
- 12
- 26
13
votes
1 answer
Getting a boost::filesystem::path as an UTF-8 encoded std::string, on Windows
We are representing paths as boost::filesystem::path, but in some cases other APIs are expecting them as const char * (e.g., to open a DB file with SQLite).
From the documentation, path::value_type is a wchar_t under Windows. As far as I know,…

Ad N
- 7,930
- 6
- 36
- 80
13
votes
2 answers
How to convert a boost::filesystem::directory_iterator to a const char *
I want to iterate over all the files in a directory and print their contents.
Boost handles the iteration part very nicely but I have no idea how to conver that into a const char *.
boost::filesystem::directory_iterator path_it(path);
…

nikhil
- 8,925
- 21
- 62
- 102
12
votes
1 answer
Expanding user path with boost::filesystem
Is there functionality in boost::filesystem to expand paths that begin with a user home directory symbol (~ on Unix), similar to the os.path.expanduser function provided in Python?

Daniel
- 8,179
- 6
- 31
- 56
12
votes
2 answers
Segmentation fault in std::transform
I'm trying to transfer parsed out the file names from regex match to the list of filesystem::path objects.
I believe that matches are valid because for_each for the same iterators and print to console work perfectly. However, I'm getting a…

amigo421
- 2,429
- 4
- 26
- 55
12
votes
4 answers
Read/Write file with unicode file name with plain C++/Boost
I want to read / write a file with a unicode file name using boost filesystem, boost locale on Windows (mingw) (should be platform independent at the end).
This is my code:
#include
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include…

Mike M
- 2,263
- 3
- 17
- 31
12
votes
1 answer
boost::filesystem::path and fopen()
I get error when I try to do this:
path p = "somepath";
FILE* file = fopen(p.c_str(), "r");
I get:
argument of type "const boost::filesystem::path::value_type *" is incompatible with parameter of type "const char *"
Could anyone tell me what I'm…

Martin
- 1,877
- 5
- 21
- 37