boost-filesystem

Inconsistent behavior of std::regex

末鹿安然 提交于 2019-12-10 18:23:40
问题 I have the following issue where: std::regex behaves differently if I pass the result of boost::filesystem::path::string() vs storing the result in a intermediate string variable. The first will return a match that is truncated and which is later not accepted by std::stoull (throws invalid_argument exception) while the second works perfectly. See the following commands that explain more the issue: [nix-shell:~]$ ls -l foo total 0 -rw-r--r-- 1 amine users 0 Aug 10 16:55 008 -rw-r--r-- 1 amine

Is boost::filesystem::directory_iterator invalidated by deletion?

假装没事ソ 提交于 2019-12-10 16:35:18
问题 I am iterating through a directory, and when an item matches some criteria, I delete it. Can I do it safely from within the loop, or to I have to save paths in an array and delete then later? I did not find a relevant information in boost::filesystem docs. 回答1: Quoting the first part of a note attached to the docs of boost::filesystem::directory_iterator (emphasis is my own): Programs performing directory iteration may wish to test if the path obtained by dereferencing a directory iterator

How to change file permissions using the Boost library?

前提是你 提交于 2019-12-10 15:27:22
问题 How can I use the Boost library to change the permissions of a file to read-only? There are some questions that I have already seen, such as this and this, but I still don't know how to do it, I have tried doing boost::filesystem::wpath path = L"abc.txt"; if( boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path ) ) { boost::filesystem::file_status s = boost::filesystem::status( path ); /* here I need to set file permissitons to READ ONLY for `path` file */ } Any ideas

How to use copy_file in boost::filesystem?

和自甴很熟 提交于 2019-12-10 12:58:32
问题 I want to copy a file from directory to another, but my program always aborts for some reasons.Has anyone done this this before could tell me what was wrong? And how could I catch exceptions was thrown by copy_file , I checked boost site, but I could not find any relevant information about exception. path user_path( "C:\\My Folder" ); boost::filesystem::create_directory( user_path ); path file( "C:\\Another\\file.txt" ); boost::filesystem::copy_file( file, user_path ); Thanks, 回答1: You have

Invalid cross-device link error with boost filesystem

爱⌒轻易说出口 提交于 2019-12-10 12:36:49
问题 I am trying to move a file from a location to another using boost::filesystem . I used boost::filesystem::rename function but when I try to do that I have the following error. terminate called after throwing an instance of 'boost::filesystem::filesystem_error' what(): boost::filesystem::rename: Invalid cross-device link: "./file_A.csv", "/opt/data/file_B.csv" Aborted (core dumped) I understood that the problem is that I am trying to move a file from one folder into another mounted on a

parent_path() with or without trailing slash

∥☆過路亽.° 提交于 2019-12-10 07:53:20
问题 As explained in the documentation, the expected output of the following is: boost::filesystem::path filePath1 = "/home/user/"; cout << filePath1.parent_path() << endl; // outputs "/home/user" boost::filesystem::path filePath2 = "/home/user"; cout << filePath2.parent_path() << endl; // outputs "/home" The question is, how do you deal with this? That is, if I accept a path as an argument, I don't want the user to care whether or not it should have a trailing slash. It seems like the easiest

C++: All boost path operations segfault (OSX / GCC)

六月ゝ 毕业季﹏ 提交于 2019-12-09 18:10:38
问题 I am getting consistent segfaults with almost any operation I am trying to perform with boost path. ( Edit: It appears that all segfaulting functions are related to current_path() ) Sample program: #include <boost/filesystem/operations.hpp> #include <boost/filesystem/path.hpp> #include <iostream> using namespace std; using namespace boost::filesystem; using namespace boost::system; int main(int argc, const char * argv[]) { error_code err; auto p = path("hello/../world"); cout << p.string() <<

Why does boost::filesystem::path::string() return by value on Windows and by reference on POSIX?

﹥>﹥吖頭↗ 提交于 2019-12-08 17:30:25
问题 From boost/filesystem/path.hpp: # ifdef BOOST_WINDOWS_API const std::string string() const { [...] } # else // BOOST_POSIX_API // string_type is std::string, so there is no conversion const std::string& string() const { return m_pathname; } [...] # endif For wstring() it is exactly the other way around - returning by reference on Windows and by value on POSIX. Is there an interesting reason for that? 回答1: On Windows, path stores a wstring , since the only way to handle Unicode-encoded paths

Why Must I Still Use -lstdc++fs?

老子叫甜甜 提交于 2019-12-07 05:17:27
问题 There have been several questions about getting experimental/filesystem to compile in the latest versions of GCC and Clang: experimental::filesystem linker error But now filesystem has been accepted into c++17 so no more need for experimental or the -lstdc++fs flag, right? Wrong I cannot even #include <filesystem> on the head version of either clang++ or g++ when I try on: http://melpon.org/wandbox Is there still some other argument I need? -lstdc++fs just gives me the experimental version,

How do I ignore hidden files (and files in hidden directories) with Boost Filesystem?

会有一股神秘感。 提交于 2019-12-06 23:19:00
问题 I am iterating through all files in a directory recursively using the following: try { for ( bf::recursive_directory_iterator end, dir("./"); dir != end; ++dir ) { const bf::path &p = dir->path(); if(bf::is_regular_file(p)) { std::cout << "File found: " << p.string() << std::endl; } } } catch (const bf::filesystem_error& ex) { std::cerr << ex.what() << '\n'; } But this includes hidden files and files in hidden directories. How do I filter out these files? If needed I can limit myself to