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

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 /my_folder/ total 4 drwxr-xr-x 8 root root 4096 Nov 2 2021…
dkish
  • 319
  • 3
  • 13
0
votes
0 answers

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 easier to explain with code - the following code…
dkish
  • 319
  • 3
  • 13
0
votes
0 answers

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-8dd824dd793e}\ Using powershell Get-ChildItem…
Claude
  • 51
  • 2
  • 7
0
votes
1 answer

std::unordered_set: 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 std::size_t removeDuplicates(std::vector& vec) { std::unordered_set seen; auto newEnd…
RL-S
  • 734
  • 6
  • 21
0
votes
1 answer

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 #include #include namespace fs =…
Happy Machine
  • 987
  • 8
  • 30
0
votes
0 answers

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 locations really need to be hard-wired, or is there a…
SMGreenfield
  • 1,680
  • 19
  • 35
0
votes
0 answers

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 shows me the files deleted (by me)
amunino
  • 9
  • 1
0
votes
0 answers

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 simplicity the case of directories, symlinks etc.), and I…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
3 answers

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\\cambarchian\\Documents\\tester"; std::filesystem::path sourcepath =…
0
votes
0 answers

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 < ft2) std::cout << "file1 is older than file2."; Unfortunately…
0
votes
1 answer

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 could be a bad thing though because anyone can run…
0
votes
1 answer

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 throwing an instance of…
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
0
votes
0 answers

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 using std::filesystem::current_path().string()…
Dark Sorrow
  • 1,681
  • 14
  • 37
0
votes
1 answer

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 #include #include #include…
rebubi
  • 11
  • 1
  • 3
0
votes
0 answers

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::FileSystem::rename(const std::string&…
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161