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

Weird behavior of push_back() a filesystem::path's .string().data() result into a "vector"

Running this program #include #include #include using namespace std; namespace fs = filesystem; int main() { vector paths{"a.o", "b.o"}; vector argv{}; for (auto &p : paths) { …
1
vote
1 answer

Return value of std::filesystem::create_directories() on paths with trailing slash

GCC (10.0.1) and Clang (11.0.0)/MSVC (VS 16.4.3) show different behavior concerning std::filesystem::create_directories() when a non-existing path with a trailing slash is given as argument. More precisely, while all three compilers indeed create…
plexando
  • 1,151
  • 6
  • 22
1
vote
1 answer

filesystem path string method returning mixed \ and /

I have a C++ program where I use recursive iterator to go through folder that I provide as an argument to program. Problem is that when I call .string on paths I get I get mixed \ and / in the path. Using .generic_string fixes this problem, but I…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
1
vote
1 answer

Replace file using std::filesystem

Often there is a pattern of writing an output to temporary file(bla.txt.tmp) deleting the original (rm bla.txt) renaming a new one(bla.txt.tmp -> bla.txt) Is there any utility function in std::filesystem to do this or I need to do steps one by one…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
1
vote
1 answer

How to convert const std::filesystem::directory_entry to tchar?

I'm trying to convert const std::filesystem::directory_entry (dirent) to tchar but I don't understand how it an be done. I tried a lot of ways. Can you help me? Edited: #include "pch.h" #include #include
Pranciskus
  • 487
  • 1
  • 6
  • 17
1
vote
1 answer

Segmentation fault when exiting from a class in which an std::filesystem::path object is specified

I face a problem in my program that I can't get over it. I have a class in which I have declared an attribute like std::filesystem::path p {"path/to/save/dir"};. And I have in the same class a method which saves some data to a .txt file. First I…
Marios Koni
  • 143
  • 1
  • 13
1
vote
1 answer

`std::filesystem::directory_iterator` compiler issue

Many people (e.g 1, 2) have asked about how to get std::filesystem::directory_iterator to work, but I'm still having trouble after I've read those. I am trying to build a small static library. After adding in the directory iterator into some source…
Taylor
  • 1,797
  • 4
  • 26
  • 51
1
vote
1 answer

std::filesystem::directory_iterator in C++/CX UWP app can't find directory?

I'm writing a cross-platform app, so thought I'd do the UI in XAML with C++/CX resp. Cocoa, and the core in standard C++. However, I'm having problems accessing documents. I present a FolderPicker and take the path and stick it in a…
uliwitness
  • 8,532
  • 36
  • 58
1
vote
1 answer

Unexpected aliasing with std::experimental::directory_iterator

I was using the experimental std::filesystem implementation in gcc 6.3.1, and ran into some very unexpected behavior with regard to std::experimental::filesystem::directory_iterator and std::distance. Specifically, after a call to std::distance, the…
Chris Fretz
  • 387
  • 1
  • 2
  • 10
0
votes
0 answers

Why std::filesystem does not have overloads for conversion from and to POSIX permissions?

I have a file with paths and permissions in POSIX octal notation. The file paths must exist and permissions are checked as per the manifest file. If mismatch, set new filesystem permissions as per manifest. Is there an easy conversion between…
0
votes
1 answer

unordered_set of std::filesystem::path as a data member

I'm trying to create a class with unordered_set of paths as data member. At first, I declared a class with this member and got error: Attempting to reference a deleted function After reading a few posts here as well as reading C++17 path class…
0
votes
1 answer

can I static_assert if a file doesn't exist at compile time?

I want to make sure resource image files that I pass to my gui are actually there during compile time. something like load_image(static_assert(!(std::filesystem::exists(pathToFile)), "Resource file " + std::string(pathToFile) + " does not…
Aaron
  • 81
  • 2
  • 9
0
votes
2 answers

how std::filesysyem works on any OS?

I recently wanted to use the header in my application, but I'm not sure if it works on any operating system. (any) because file systems are platform-os dependent. I understand that one of C++'s purposes is cross-platform compilation, but how can it…
Another HM
  • 148
  • 10
0
votes
1 answer

Check if a file is in the current directory or its children using C++

I am writing a small HTTP web server in C++ as part of a hobby project, and I need to serve static files. However, one problem I want to avoid is a user typing in, for example, http://example.com/../passwd. To ensure that users don't enter in a…
bsdsylvia
  • 75
  • 5