Questions tagged [std-filesystem]

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

Filter by
Sorted by
Tagged with
1 vote
2 answers
80 views

Choose recursive/non-recursive directory iterator based on a run-time condition

I want to use methods std::filesystem::directory_iterator or std::filesystem::recursive_directory_iterator depending on a boolean. The code would be something like: some_type dirIterator = isRecursive ...
andre pacheco's user avatar
1 vote
0 answers
49 views

How to avoid fs::directory_iterator exceptions

I'm using the following loop to extract names of files and directories from a root path. for (const auto& entry : fs::directory_iterator(dirToList, fs::directory_options::skip_permission_denied, ...
noob_user's user avatar
1 vote
0 answers
58 views

std::filesystem::create_directory permissions differes from reality

At cpp reference (std::filesystem::create_directory) - we can see the follow descriptrion: Creates the directory p as if by POSIX mkdir() with a second argument of static_cast(std::filesystem::perms::...
fsmoke's user avatar
  • 145
1 vote
1 answer
105 views

std::filesystem directory walk unstable with concurrent processes

I am trying to write a cross-platform globbing method in C++. For this, I am trying to use the std::filesystem library to recurse through directories and compare paths against a provided path regex. ...
Mohamed Ayman Aly's user avatar
1 vote
0 answers
132 views

C++ std::filesystem::directory_iterator does not iterate over regular files on Android

I tried to write a program that renamed certain files on my phone in a certain way, for this I used std::filesystem: for (const auto& entry : std::filesystem::directory_iterator{ start_path }) { ...
God I Hate Python's user avatar
0 votes
0 answers
77 views

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 ...
Nikolay Kosev's user avatar
0 votes
1 answer
132 views

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 ...
MorMordoch's user avatar
0 votes
1 answer
192 views

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 ...
Aaron's user avatar
  • 81
1 vote
1 answer
137 views

fs::recursive_directory_iterator command doesn't iterate over sub-directories under a symbolic link

I found that the toy implementation of recursive_directory_iterator furnished below doesn't iterate over sub-directories under symbolic links. So the sub-directories under a symbolic link folder are ...
seccpur's user avatar
  • 5,006
0 votes
2 answers
63 views

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 ...
Another HM's user avatar
0 votes
1 answer
66 views

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/../...
bsdsylvia's user avatar
0 votes
2 answers
374 views

std::filesystem::recursive_directory_iterator and read permision

Under Linux: I am trying to access a folder using 'recursive_directory_iterator' and it is throwing a "Permission denied" exception. Here are the permissions for the given folder: ls -l /...
dkish's user avatar
  • 319
0 votes
0 answers
433 views

std::filesystem::path::parent_path() behavior

When setting a path by passing just a file name to mean, the path is current_path() + filename, it seems std::filesystem::path recognizes a parent path only when explicitly given as relative path. Its ...
dkish's user avatar
  • 319
0 votes
0 answers
70 views

How to use the UNC format to specify a full root-name in Windows

I am trying to work with UNC to access files on Windows on a partition that does not have a drive letter. The UNC I am trying to use (as returned by mountvol) is \\?\Volume{6ed63a9f-b672-4f57-8c22-...
Claude's user avatar
  • 51
0 votes
1 answer
346 views

std::unordered_set<std::filesystem::path>: compile error on clang and g++ below v.12. Bug or user error?

I added the following function template to my project, and a user complained that it wouldn't compile on their system anymore: template<typename T> std::size_t removeDuplicates(std::vector<T&...
RL-S's user avatar
  • 734
1 vote
0 answers
584 views

C++20 filesystem: recursive_directory_iterator fails with filesystem_error if subdirectory is deleted, despite nothrow function

I am running a few hundred different unit-tests on MacOS Intel, MacOS Silicion, Windows x64 and Linux(Ubuntu) x64 of a function that makes use of fs::recursive_directory_iterator(..). In one test I ...
HelloWorld's user avatar
  • 2,402
1 vote
0 answers
344 views

std::filesystem fails on Windows (Visual Studio 2017)

The following code throws an exception when compiled on Windows 10 with Visual Studio 2017 but runs fine on POSIX OS (macOS, Linux): #include <iostream> #include <filesystem> int main() {...
Stéphane Mottelet's user avatar
1 vote
3 answers
517 views

std::system::error exception during recursive_directory_iterator | Unicode Translation Exception 1113 in C++

I was working on a bigger project using the recursive_directory_iterator of std::filesystem, when I stumbled upon this seemingly unknown/unfixable error. I simplified the project to the bare minimum ...
Gisbert12843's user avatar
2 votes
3 answers
584 views

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 ...
Nikolaj's user avatar
  • 1,137
2 votes
1 answer
428 views

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 ...
Christian's user avatar
0 votes
1 answer
1k views

std::filesystem example not compiling on c++ 17

I cant compile this official cpp filesystem reference example using c++ 17 clang: https://en.cppreference.com/w/cpp/filesystem/recursive_directory_iterator #include <fstream> #include <...
Happy Machine's user avatar
6 votes
3 answers
697 views

Version of std::filesystem::equivalent for non-existing files

My program is supposed to create two files with user-specified paths. I need to know if the paths lead to the same location, to end with an error before I start changing the filesystem. Because the ...
Piotr Siupa's user avatar
  • 3,929
0 votes
0 answers
78 views

Portable method in C++ to determine special folder locations (Downloads, Documents, Preferences, etc.)

I've been searching for a portable method in Boost or C++17 std::filesystem (or POSIX) to determine the system sanctioned locations of the user's Documents, Downloads, and Preferences. Do these ...
SMGreenfield's user avatar
  • 1,680
-1 votes
1 answer
169 views

How can i get all files from disk?

I have to create a vector of all files on my disk, starting from root ("C:/"). I used filesystem library and recursive_directory_iterator, however program throws filesystem::filesystem_error ...
dummygum's user avatar
0 votes
0 answers
91 views

std::filesystem sees deleted files

Why std::filesystem sees deleted files? for (auto& file : std::filesystem::recursive_directory_iterator(game_folder)) { cout << file.path().string().c_str() << endl; } this code ...
amunino's user avatar
12 votes
1 answer
2k views

What does std::filesystem::is_regular_file(path) mean on Windows?

About std::filesystem::is_regular_file(path), cppreference.com says: Checks if the given file status or path corresponds to a regular file […] Equivalent to s.type() == file_type::regular. For ...
Amit's user avatar
  • 709
2 votes
3 answers
2k views

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 (...
ante.ceperic's user avatar
5 votes
0 answers
2k views

How do I use std::filesystem to see if I have write access?

I want to use std::filesystem to query about a disk folder path that was given to my function. I want to find out if I have write access to the folder. But I want to do it without actually trying to ...
Joe's user avatar
  • 5,425
0 votes
0 answers
867 views

Portably check whether a file is readable

I'm asking the cross-platform version of this question: C++: How to check if a file/directory is readable? (PHP equivalent: is_readable) I have a filesystem::path of a file (let's ignore for ...
einpoklum's user avatar
  • 119k
0 votes
3 answers
2k views

Error with std::filesystem::copy copying a file to another pre-existing directory

See below for the following code, and below that, the error that follows. std::string source = "C:\\Users\\cambarchian\\Documents\\tested"; std::string destination = "C:\\Users\\...
Christopher Ambarchian's user avatar
8 votes
1 answer
4k views

How to properly handle windows paths with the long path prefix with std::filesystem::path

std::filesystem::path doesn't seem to be aware of the windows long path magic prefix. Is this per design or is there a mode/flag/compiler switch/3rd party library which can be used? f.e. for a path ...
ridilculous's user avatar
0 votes
0 answers
690 views

C++ std::filesystem::last_write_time operator< sometimes not correct?

I want to compare the file age of two files. I tried this: auto ft1 = std::filesystem::last_write_time("file1"); auto ft2 = std::filesystem::last_write_time("file2"); if (ft1 < ...
Markus Donath's user avatar
0 votes
1 answer
433 views

Can std::filesystem::permissions change secure file permissions

I have been experimenting, with the std::filesystem and I came across the permissions function, which allows you to change the access permissions that users have to files. This seems almost like it ...
Gary Fisher's user avatar
7 votes
2 answers
10k views

Check if directory exists using <filesystem>

I have a string that contains the path to some file. The file doesn't need to exist (in my function it can be created), but it's necessary that directory must exist. So I want to check it using the &...
Dark_Phoenix's user avatar
0 votes
1 answer
2k views

std::filesystem::remove_all fails on read-only file

I am trying to remove a complete git repository clone from my disk using std::filesystem::remove_all() std::filesystem::remove_all( myRepoName ); This throws an exception terminate called after ...
ravenspoint's user avatar
  • 19.2k
1 vote
1 answer
253 views

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 ...
Mochideer's user avatar
1 vote
1 answer
500 views

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)) ...
Ethan McTague's user avatar
0 votes
0 answers
1k views

Unable to get path from std::filesystem in global static object

Build Environment: Visual Studio 2022 Windows 10 64-bit C++ Standard : C++20 I am trying to get the directory of my executable file. In my earlier code based on C++17 standard I could read the path ...
Dark Sorrow's user avatar
  • 1,681
1 vote
1 answer
132 views

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 ...
piponazo's user avatar
  • 478
4 votes
0 answers
536 views

create all folder in a big path (with subfolders) [closed]

Im trying to create all folder in a path that reach to a file, for that by a little search I found out about std::filesystem::create_directories its ok but the problem of using it is looks like its ...
file-tracer's user avatar
1 vote
1 answer
394 views

‘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 ...
Kong's user avatar
  • 2,202
0 votes
1 answer
255 views

Cannot use filsesystem in ROS node

I'm trying to use std::filesystem to open a folder and iterate through its files, sorted by name. I'm using the code from this question inside a very basic ros package: node.cpp #include <ros/ros.h&...
rebubi's user avatar
  • 11
0 votes
0 answers
143 views

Is there an equivelent of Win32 API MoveFileEx() in C++ filesystem?

I am porting a codebase that depends on Win32 API to C++ 17. There is a class that is responsible for handling files. The function I am currently looking at looks like this: bool project::filesystem::...
rbaleksandar's user avatar
  • 8,723
1 vote
0 answers
931 views

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 ...
Ma Ta's user avatar
  • 69
0 votes
1 answer
618 views

How to check if std::filesystem::copy is ended?

Copying files to a directory to another directory using this code auto const copyOption = std::filesystem::copy_options::recursive | std::filesystem::copy_options::skip_symlinks; std::filesystem::copy(...
kramer's user avatar
  • 177
2 votes
1 answer
617 views

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 ...
Stefan F.'s user avatar
6 votes
2 answers
831 views

`std::filesystem::directory_iterator` graceful handling of non-existing dir

I have the following code: for (const auto& x : std::filesystem::directory_iterator(dir)) { // do stuff with x } dir might not exist, and I want to treat this case as if the dir is empty. I ...
Paul's user avatar
  • 6,127
4 votes
2 answers
478 views

Why can't I insert this transformed directory_iterator into a vector?

I am trying to insert a transformed range of directory entries into a vector using its insert(const_iterator pos, InputIt first, InputIt last) member function template. Unfortunately I can't get the ...
neop's user avatar
  • 89
0 votes
2 answers
1k views

iterating through all the directories and subdirectories in c++

I wanted to use the std::filesystem::recursive_directory_iterator class to create a class method iterating through all subdirectories and processing found xml files. The only way I have found on the ...
skrzypin's user avatar
1 vote
1 answer
329 views

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 ...
Adrian McCarthy's user avatar