The Boost.Filesystem library provides facilities to manipulate files and directories, and the paths that identify them.
Questions tagged [boost-filesystem]
353 questions
11
votes
4 answers
Why does std::filesystem provide so many non-member functions?
Consider for example
file_size. To get the size of a file we will be using
std::filesystem::path p = std::filesystem::current_path();
// ... usual "does this exist && is this a file" boilerplate
auto n = std::filesystem::file_size(p);
Nothing…

dlw
- 323
- 2
- 14
11
votes
0 answers
boost::filesystem::create_directories(".") fails
boost::filesystem::create_directories(".") always fails on my system. It seems like this might be a bug, but after reading the documentation I'm not entirely sure. Here's an example program:
#include
#include
int…

John Zwinck
- 239,568
- 38
- 324
- 436
11
votes
6 answers
Linker errors when using boost::filesystem?
I have the following code:
#include
#include
int main(){
const char* file_path = "my_path";
std::cout << boost::filesystem::file_size(file_path) << std::endl;
}
and when I build I get the following…

user997112
- 29,025
- 43
- 182
- 361
10
votes
2 answers
C++:boost file system to return a list of files older than a specific time
I am using the Boost::FileSystem library with C++ running under Linux platform and I have a question following:
I would like to have a list of files which are modified older than a given date time. I don't know whether the boost::FileSystem offer…

olidev
- 20,058
- 51
- 133
- 197
10
votes
2 answers
Extract the parent folder of a directory using boost::filesystem
Suppose I have the following folder
std::string m("C:\MyFolderA\MyFolderB\MyFolderC");
boost::filesystem::path p(m);
Is there anyway for me to extract the parent of this folder. I want to get the string MyFolderB. from the above path.

James Franco
- 4,516
- 10
- 38
- 80
9
votes
2 answers
How to create a folder in the home directory?
I want to create a directory path = "$HOME/somedir".
I've tried using boost::filesystem::create_directory(path), but it fails - apparently the function doesn't expand system variables.
How can I do it the simplest way?
(note: in my case the…

lampak
- 890
- 1
- 9
- 21
9
votes
1 answer
How to use copy_file in boost::filesystem?
I want to copy a file from directory to another, but my program always aborts for some reasons.Has anyone done this this before could tell me what was wrong? And how could I catch exceptions was thrown by copy_file, I checked boost site, but I could…

roxrook
- 13,511
- 40
- 107
- 156
9
votes
1 answer
Which compilers support std::filesystem?
Thanks to C++11, after a long relationship with boost, the last component that makes me depend on it is the filesystem. std::filesystem seems to be implemented as experimental according to the link: Filesystem library
Since it mimics…

deniz
- 2,427
- 4
- 27
- 38
9
votes
4 answers
C++ / Boost Filesystem - mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600'
I'm new to C++ and Boost. I'm doing a small simple program to trying to learn the Boost Filesystem library. I have followed the directions to build the Boost libs. And now when I try to compile this simple code I get 6 of these errors.
Error 5 …

BuddyJoe
- 69,735
- 114
- 291
- 466
9
votes
3 answers
Should boost::filesystem::exists really throw an exception for removable media device with no media?
I've run into a bit of an odd circumstance while using boost::filesystem::exists. If you attempt to check for the existance of a file on a drive that isn't ready or has no media in it, it throws a basic_filesystem_error. As far as I'm concerned…

Perculator
- 1,293
- 1
- 10
- 12
8
votes
3 answers
how to use C++ to get the folder/directory name, but not the path of one file? Especially boost::filesystem;
std::string file="C:\\folder1\\folder2\\folder3.txt";
fs::path file_path(file);
fs::path file_dir=file_path.parent_path();// "C:\\folder1\\folder2";
std::string str_path=file_path.string();
std::string str_dir=file_dir.string();
std:string…

Pengju Zhao
- 1,439
- 3
- 14
- 17
8
votes
2 answers
How do I ignore hidden files (and files in hidden directories) with Boost Filesystem?
I am iterating through all files in a directory recursively using the following:
try
{
for ( bf::recursive_directory_iterator end, dir("./");
dir != end; ++dir )
{
const bf::path &p = dir->path();
…

Soverman
- 1,135
- 1
- 9
- 16
7
votes
2 answers
How to get file permissions with c++ boost library?
I am working on a project to make a database of the files I have on current directory. And one of the details I want about my files is the file permissions that are set with chmod in ubuntu. (just a note: I will be needing the group and owner info…

Logan
- 10,649
- 13
- 41
- 54
7
votes
2 answers
Why does std::filesystem::path::append replace the current path if p starts with root path
Given below code:
#include
#include
namespace fs = std::filesystem;
int main()
{
fs::path fsBase = "/base";
fs::path fsAppend = "/append";
auto fsResult = fsBase / fsAppend;
std::cout << "fsResult: " <<…

Mine
- 4,123
- 1
- 25
- 46
7
votes
1 answer
Why Must I Still Use -lstdc++fs?
There have been several questions about getting experimental/filesystem to compile in the latest versions of GCC and Clang: experimental::filesystem linker error
But now filesystem has been accepted into c++17 so no more need for experimental or the…

Jonathan Mee
- 37,899
- 23
- 129
- 288