Questions tagged [std-filesystem]

c++ std::filesystem discussion, std::filesystem was added to the ISO C++ standard library in C++17

Specification available from http://en.cppreference.com/w/cpp/filesystem

165 questions
1
vote
1 answer

C++ MFC reading Cstring from editbox for file reading (std::filesystem Exception unhandled memory problem)

What my code is suppose to achieve is to read in the file names after given a file path input and output (switch 1: the files under the same folder)(switch 2: all the file names under the directory including sub-directories), and to not store the…
Mochideer
  • 35
  • 8
1
vote
1 answer

recursive_directory_iterator's skip_permission_denied option appears to be ignored on macOS?

Using C++20 and std::filesystem::recursive_directory_iterator on macOS, this code: for (auto& f : recursive_directory_iterator(getenv("HOME"), directory_options::skip_permission_denied)) { // dummy } Which should, according to my understanding…
Ethan McTague
  • 2,236
  • 3
  • 21
  • 53
1
vote
1 answer

What type would you use for passing file paths in your C++ library API?

Since I started using C++17 every time I have to develop a new library I consider several alternatives for passing file paths to public functions/methods. These are some of my thoughts I normally have regarding this topic: By using…
piponazo
  • 478
  • 2
  • 4
  • 10
1
vote
1 answer

‘operator/’ is not a member of ‘std::filesystem’; did you mean ‘operator~'

I am trying to install the MMMTools https://mmm.humanoids.kit.edu/installation.html. My cmake version is 3.16.3. I went through every step without any errors until this section cd ~/MMMCore mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release…
Kong
  • 2,202
  • 8
  • 28
  • 56
1
vote
0 answers

Segmentation fault with std::filesystem path object

I have recently started using std::filesystem, and I have faced an issue that I could not fix. I have a class with a function that periodically iterates over some directories and in case new files are found, it adds its name and size to a map…
Ma Ta
  • 69
  • 4
1
vote
1 answer

No reverse iterators for `std::filesystem::path`?

Is there a technical reason why std::filesystem::path doesn't offer reverse iterators (i.e., rbegin and rend)? If I have a std::filesystem::path for /a/b/c/b/d/b/e and I want to find the first component that matches b, I can use std::find(p.begin(),…
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
1
vote
1 answer

C++ directory item iteration without exceptions

In C++17 it became easy to iterate over the items in some directory dir: for ( auto& dirEntry: std::filesystem::directory_iterator(dir) ) { if ( !dirEntry.is_regular_file() ) continue; ... Unfortunately this way may throw exceptions, which I want…
Fedor
  • 17,146
  • 13
  • 40
  • 131
1
vote
2 answers

VS error from std::filesystem::u8path(const char8_t*)

In this simple C++20 program #define _SILENCE_CXX20_U8PATH_DEPRECATION_WARNING //suppress VS warning #include int main() { auto p = std::filesystem::u8path(u8"a"); } I get the error from Visual Studio 2019 16.10.0 in stdcpplatest…
Fedor
  • 17,146
  • 13
  • 40
  • 131
1
vote
1 answer

Getting the path of recursively iterated directories relative to the specified entry path

Consider the example in the documentation of std::filesystem::recursive_directory_iterator: #include #include #include namespace fs = std::filesystem; int main() { fs::current_path(fs::temp_directory_path()); …
DarioP
  • 5,377
  • 1
  • 33
  • 52
1
vote
2 answers

How can i return an error to std::filesystem?

For example, this is how I do it using runtime_error #include #include std::exception &foo(){ try { if(!std::filesystem::is_directory(std::filesystem::path("sdfsdf"))){ throw…
wecandoit
  • 23
  • 1
  • 5
1
vote
1 answer

Output for directory_entry conflicts with overloaded ostream operator<< for class with variant

I have a project where I print std::filesystem::directory_entry from directory_iterator. On the other side, I have a completely independent class with overload std::ostream& operator<<, that has a templated constructor, which initializes a…
Askold Ilvento
  • 1,405
  • 1
  • 17
  • 20
1
vote
1 answer

c++ 17 filesystem::recursive_directory_iterator() gives error no such directory on mac but works on windows

Configurations macOS: 10.15.5 xcode: 11.5 clang: 11.0.3 Project is set to c++17 I am new to macOS and trying to solve a simple problem.. #include #include using namespace std; namespace fs = std::filesystem; int main(int…
AtiqGauri
  • 1,483
  • 13
  • 26
1
vote
1 answer

Mac c++ filesystem library not recognized

NOTE: this does not fail to #include . It fails afterward. I’m on a macOS 10.15, using clang 11. Output of clang --version: Apple clang version 11.0.0 (clang-1100.0.33.17) Target: x86_64-apple-darwin19.4.0 Thread model:…
owengall
  • 455
  • 4
  • 11
1
vote
0 answers

Compilation fail with "std::filesystem" on raspberry

I have "Raspberry Pi 3 Model B" with "Raspbian Buster with desktop" installed on SD-card. I installed all the necessary to compile with g++: gcc (Raspbian 8.3.0-6+rpi1) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software;…
debugasm
  • 11
  • 1
1
vote
0 answers

std::filesystem copy_file failure

I am trying to make a copy of a file. This code runs without error, but the copied file is incomplete: #include #include using namespace std; int main() { error_code ec; filesystem::copy_file( …
ravenspoint
  • 19,093
  • 6
  • 57
  • 103