Questions tagged [boost-filesystem]

The Boost.Filesystem library provides facilities to manipulate files and directories, and the paths that identify them.

341 questions
50
votes
4 answers

how to perform boost::filesystem copy_file with overwrite

The Windows API function CopyFile has an argument BOOL bFailIfExists that allows you to control whether or not you want to overwrite the target file if it exists. The boost::filesystem copy_file function has no such argument, and will fail if the…
Dani van der Meer
  • 5,998
  • 3
  • 24
  • 45
32
votes
2 answers

boost directory_iterator example - how to list directory files not recursive

How should I use directory_iterator to list directory files (not recursive)? Also what header files / libs should I add/link or other settings I should make? I'm using boost in my project but by some reason directory_iterator is "underclared…
Oleg Vazhnev
  • 21,122
  • 47
  • 154
  • 286
32
votes
5 answers

boost::filesystem get relative path

What methods of the boost::filesystem library can help me to get a path relative to another path? I have a path /home/user1/Downloads/Books and a path /home/user1/. Now I want to get a path Downloads/Books.
itun
  • 3,121
  • 11
  • 47
  • 72
31
votes
7 answers

Get relative path from two absolute paths

I have two absolute filesystem paths (A and B), and I want to generate a third filesystem path that represents "A relative from B". Use case: Media player managing a playlist. User adds file to playlist. New file path added to playlist relative to…
Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
29
votes
2 answers

How similar are Boost.Filesystem and the C++ standard filesystem library?

I need a filesystem library for use with a C++11-capable compiler or a C++14-capable one - so it can't be be from C++17. Now, I know that the filesystem library going into C++17 is based based on Boost::Filesystem; but - are they similar enough…
einpoklum
  • 86,754
  • 39
  • 223
  • 453
26
votes
2 answers

What is the C++17 equivalent to boost::filesystem::unique_path()?

std::filesystem on C++17, and std::experimental::filesystem for many pre-C++17 compilers, are based on boost::filesystem and almost all of it is obvious to port to the newer std. But I see no std::filesystem equivalent to…
Larry Gritz
  • 12,031
  • 5
  • 40
  • 40
26
votes
8 answers

expand file names that have environment variables in their path

What's the best way to expand ${MyPath}/filename.txt to /home/user/filename.txt or %MyPath%/filename.txt to c:\Documents and settings\user\filename.txt with out traversing the path string looking for environement variables directly? I see that…
Dan
  • 1,199
  • 3
  • 12
  • 19
25
votes
1 answer

boost::filesystem exists() on directory path fails, but is_directory() is ok

I'm getting path to current directory with boost filesystem, then checking if the directory exists. is_directory() is ok, but exists() fails on the same path, am I missing something? Example code (boost 1.35): #include…
stefanB
  • 69,149
  • 26
  • 113
  • 140
24
votes
4 answers

C++ BOOST undefined reference to `boost::filesystem::detail::copy_file

I have no clue why boost::filesystem::copy_file is making trouble for me. undefined reference to `boost::filesystem::detail::copy_file // g++ -std=c++11 test.cpp -lboost_filesystem -lboost_system -lrt -lboost_wave #include…
ar2015
  • 4,338
  • 4
  • 36
  • 83
19
votes
2 answers

Why is there no boost::filesystem::move_file?

I'm using boost filesystem to replace windows C++ functions like CopyFile and MoveFile to get some kind of portability between windows and linux. I'm using copy_file but I have not been able to find anything that moves files like a 'move_file'…
molholm
  • 1,852
  • 3
  • 22
  • 27
18
votes
3 answers

Iterate over all files in a directory using BOOST_FOREACH

Can you iterate over all files in a directory using boost::filesystem and BOOST_FOREACH? I tried path dirPath = ... int fileCount = 0; BOOST_FOREACH(const path& filePath, dirPath) if(is_regular_file(filePath)) ++fileCount; This code…
Johan Råde
  • 18,399
  • 19
  • 62
  • 103
17
votes
3 answers

Obtain platform's path separator using Boost.Filesystem

Is there a way to obtain the platform's path separator character using Boost.Filesystem? By path separator, I mean / for Unix and \ for Windows. I already know I can use boost::filesystem::path::operator/ to concatenate two paths together with the…
Emile Cormier
  • 26,080
  • 13
  • 87
  • 116
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
  • 19,419
  • 5
  • 72
  • 137
16
votes
1 answer

How to avoid removing directory on remove_all with Boost Libraries?

I'm using boost::filesystem::remove_all operation to remove the content of a directory. It removes correctly the content, but, as state by Boost Filesystem Documentation, it also removes the directory itself. Is there an easy way to stay with the…
Santiago Agüero
  • 2,933
  • 7
  • 23
  • 36
15
votes
6 answers

Boost.Filesystem how to find out in which directory your executable is?

So I run my app. I need for it to know where its executable is. How to find path to it using Boost.Filesystem?
Rella
  • 59,216
  • 102
  • 341
  • 614
1
2 3
22 23