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
2
votes
2 answers

Potential bug in std::filesystem::remove_all with clang++

DO NOT TRY THIS AT HOME I am having a weird issue with std::filesystem::remove_all. I have written a program that writes N files to disk in a single directory and then deletes all the files afterward (there is a good reason for this). However, when…
Lars Nielsen
  • 2,005
  • 2
  • 25
  • 48
2
votes
1 answer

Non-empty relative current path, in standard C++?

With C++17 (or Boost::filesystem), we can get the current path / current working directory using filesystem::current_path(). However - that gives us an absolute path. We could also use an empty path as the relative current path - sometimes. But - is…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
0 answers

Is it possible to refactor _wfopen to std::filesystem?

I want to refactor this code in C++17. Can I use std::filesystem in this case? #if defined(BOOSTER_WIN_NATIVE) bool open(std::string const &file_name,std::string const &encoding) { close(); // // Under Windows, we have to use…
2
votes
1 answer

How to detect usability on OSX?

I wanted to do some cross-platform, optional usage of std::filesystem and used code like the below: #ifdef __has_include #if __has_include() #include #endif #endif #ifdef __cpp_lib_filesystem #include // Use of…
Flamefire
  • 5,313
  • 3
  • 35
  • 70
2
votes
1 answer

Is lexically_normal() redundant on a call to std::filesystem::canonical() or std::filesystem::weakly_canonical()?

Would there be a reason to call lexically_normal in either of these cases: std::filesystem::path filepath = someFuntionThatGetsAPath(); filepath = std::filesystem::canonical (filepath).lexically_normal (); filepath =…
michig54
  • 21
  • 2
2
votes
0 answers

Searching a file using std::filesystem and multithreading

I wrote a program to search a file by name on system using std::filesystem (recursive search using std::filesystem::recursive_directory_iterator). It works properly if I use only one main thread, execution time ~1 second, if I start from root ("/")…
2
votes
1 answer

Strange operator/ of std::filesystem::path

auto path = std::filesystem::path("c:") / "PosteClient.log"; results in c:PosteClient.log instead of c:\PosteClient.log This is a strange behavior for me as the result on windows can't be used e.g. CreateFile("c:PosteClient.log") fails with…
usurpbrain
  • 21
  • 2
2
votes
1 answer

why does std::filesystem::path::root_name() return empty string?

I have below sample code which I ran on visual studio 2019 and on https://godbolt.org/. I can see that there are two different behavior. What could be the possible reason ? #include #include int main() { …
Praveer Kumar
  • 912
  • 1
  • 12
  • 25
2
votes
1 answer

Why is std::filesystem::file_size on directories left to the implementaiton?

So I have the following problem: I need to summarise the byte size of all files in a specific directory, this includes the size of the sub-directories, as in my case they actually can increase in size. But if we run this code on a directory that…
Lars Nielsen
  • 2,005
  • 2
  • 25
  • 48
2
votes
0 answers

Is it correct that std::filesystem::operator==() returns false when comparing two unc paths with different path separators?

I just fell over the following behavior of std::filesystem::path compiling with Visual Studio 16.0.0 and I wonder if it is correct. #include int main() { std::filesystem::path absPath1("c:\\foo\\bar"); std::filesystem::path…
Knitschi
  • 2,822
  • 3
  • 32
  • 51
2
votes
1 answer

CMake idiom for overcoming libstdc++ filesystem weirdness?

If you build C++14 code with G++ and libstdc++, there's a library named libstdc++fs, which is separate from the rest of libstdc++, and contains the code for std::experimental::filesystem. If you don't link against it, you'll get undefined…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
1 answer

Does CPP provide a way to figure out which of the filesystem perms apply?

(This is intended as a specific query regarding the newer standards like C++17) the filesystem headers now provide a way to get the permissions on a path, formatted in the standard 3 perms way (owner, group, other). How would one determine which of…
2
votes
1 answer

Which versions of GCC and clang support std::filesystem/std::experimental::filesystem?

I'm using GCC 7.4.0 and clang 6.0.0 and they both seem to have an implementation of filesystem in . since the project that i'm working on requires std::filesystem, i want to know which versions (Major + Minor) of them…
user10777785
2
votes
1 answer

What does *--end() mean in C++?

Looking at this cppreference.com page for std::filesystem::path::filename, the method's description is literaly just "equivalent to relative_path().empty() ? path() : *--end()". I've never seen that syntax "*--end()". I can figure out what it does…
Matheus Leão
  • 417
  • 4
  • 12
2
votes
1 answer

c++ - double free when using std::filesystem::path in a vector

I'm working on a bare-bones file browser using DearImgui. For this i'm using std::filesystem with g++-9 and am currently testing on Kubuntu 19.04. For the most part the program works as expected. A button is used to descend into the parent directory…
Miami
  • 69
  • 1
  • 3