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
3
votes
1 answer

UTF8 to UTF16 conversion using std::filesystem::path

Starting from C++11 one can convert UTF8 to UTF16 wchar_t (at least on Windows, where wchar_t is 16 bit wide) using std::codecvt_utf8_utf16: std::wstring utf8ToWide( const char* utf8 ) { std::wstring_convert>…
Fedor
  • 17,146
  • 13
  • 40
  • 131
3
votes
1 answer

Gnuplot and std::filesystem::remove

I'm trying to use gnuplot from C++ application, gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04). I've encountered strange behavior concerning plotting to files. So, the reproducible example is: #include #include int…
Suthiro
  • 1,210
  • 1
  • 7
  • 18
3
votes
1 answer

How copy folders and files recursively without losing file modification time?

I'm looking for simple way to copy folders recursively without losing files and folders timestamp. I find std::filesystem::copy so simple and easy to use, but it set files modification times to now.
alihardan
  • 183
  • 1
  • 14
3
votes
1 answer

Linking to stdc++fs with C++20 still necessary when using filesystem?

I began using experimental::filesystem when it had just come out and I was advised to link in stdc++fs using target_link_libraries(MyTarget stdc++fs) in CMake. My programme builds either way but may I be breaking something/ doing something…
Hirek
  • 435
  • 3
  • 12
3
votes
1 answer

Why do std::filesystem::path::compare() and boost::filesystem::path::compare() differ?

Given the following code: fs::path p{ "a/b/" }; fs::path q{ "a/b/." }; assert(p == q); [Note the extra dot at the end of the string defining q.] With the above, boost::filesystem accepts p == q as true, but gcc's and llvm's…
Curious
  • 128
  • 5
3
votes
1 answer

[LLVM-9 clang-9 OSX]: std::filesystem::path unrecognized

Hello after upgrading on OSX Mojave to the version LLVM-9 using brew upgrade llvm I got the following error: In file included from…
roman Sztergbaum
  • 671
  • 1
  • 5
  • 11
3
votes
1 answer

'Attempt to dereference a past-the-end iterator' when sorting a vector of filesystem paths

I'm writing a simple file chooser using std::filesystem. The entries of the current directory are stored in a vector. When I try to sort the vector with std::sort the program crashes. This happens with g++-9 on Ubuntu 19.04. The file is compiled…
Miami
  • 69
  • 1
  • 3
3
votes
1 answer

How does one test if a file is LOCKED and/or read-only without opening?

Is there a portable (std::filesystem) method of testing if a file is "locked" or has "read-only" permissions? MacOS Finder, for example, has a "Locked" setting, which is DIFFERENT than the standard POSIX "permissions". I need to test if a file can…
SMGreenfield
  • 1,680
  • 19
  • 35
3
votes
1 answer

How to avoid std::filesystem linker errors with Qt?

I would like to use the std::filesystem with Qt 5.12.0 with the g++ version Ubuntu 8.2.0-7ubuntu1, but getting linker errors: g++ -lstdc++fs -Wl,-rpath,/home/user/Qt/5.12.0/gcc_64/lib -o qf_filesystem_test main.o -L/home/user/Qt/5.12.0/gcc_64/lib…
AGK
  • 95
  • 2
  • 7
3
votes
1 answer

How to replace the base parameter removed from boost::filesystem::weakly_relative and std::filesystem::canonical

The function boost::filesystem::canonical() (doc of 1.66, doc of current release) offers two arguments (ignoring the error code overload) base. The first one is the path to canonicalize, the second argument is the base path used to make the first…
Brandlingo
  • 2,817
  • 1
  • 22
  • 34
3
votes
1 answer

std::experimental::filesystem::recursive_directory_iterator skip folder and its subfolder

I need to recursively search files into one directory and its subdirectory but I want to exclude one path (with its files and subdirectory) from the search. I'm using std::experimental::filesystem::recursive_directory_iterator and pop() modifier but…
gimiki
  • 83
  • 8
2
votes
3 answers

c++ 17 std::filesystem can not run on other (windows 10) computer

I have a program, compiled using MinGW on and for windows 10, I want this program to run on other peoples computers, even if they do not have MinGW or any c++ compilers installed. Normally, this is easy. I just include the exe file and the dll files…
Nikolaj
  • 1,137
  • 10
  • 22
2
votes
1 answer

Recommended way of passing file paths in Qt application

in the codebase (C++ and Qt5) I am working on, filepaths are passed as QString parameters most of the time. In some cases it is also a combination of QDir and QString. Examples: void foo(const QString &filename); void foo(const QDir pathToFile,…
Christian
  • 31
  • 3
2
votes
3 answers

Check if a path is valid, even if it doesn't exist

Let's say I have a program that takes paths to the input and output directories from a command line. If the output directory doesn't exist, our program needs to create it. I would like to check (preferably using std::filesystem) if that path is…
ante.ceperic
  • 263
  • 2
  • 9
2
votes
1 answer

Q: Boost Program Options using std::filesystem::path as option fails when the given path contains spaces

I have a windows command line program using Boost.Program_Options. One option uses a std::filesystem::path variable. namespace fs = std::filesystem; namespace po = boost::program_options; fs::path optionsFile; po::options_description desc(…