boost-filesystem

boost::filesystem::path and fopen()

我的未来我决定 提交于 2019-12-04 01:26:10
I get error when I try to do this: path p = "somepath"; FILE* file = fopen(p.c_str(), "r"); I get: argument of type "const boost::filesystem::path::value_type *" is incompatible with parameter of type "const char *" Could anyone tell me what I'm doing wrong? Thanks If you're under Windows, that value_type is wchar_t , and will fail in the conversion for fopen (that needs a char* ). As per the documentation, it seems you have to use the string() method to obtain a standard string with a default code conversor ( wchar_t -> char ): FILE* file = fopen(p.string().c_str(), "r"); 来源: https:/

how to get file names vs directory names in c++ (using boost filesystem library)

十年热恋 提交于 2019-12-03 21:48:14
When I use boost::filesystem to get a list of file names in a directory, I receive file names as well as directory names: #include <string> #include <iostream> #include <boost/filesystem.hpp> using namespace std; using namespace boost::filesystem; int main() { path p("D:/AnyFolder"); for (auto i = directory_iterator(p); i != directory_iterator(); i++) { cout << i->path().filename().string() << endl; } } Output is like: file1.txt file2.dat Folder1 //which is a folder Is there a quick way to distinguish between files and folders? My OS is Windows 8.1, if it matters. is_directory() boost:

Obtain platform's path separator using Boost.Filesystem

半城伤御伤魂 提交于 2019-12-03 11:36:24
问题 Is there a way to obtain the platform's path separator character using Boost.Filesystem? By path separator, I mean / for Unix and \ for Windows. I already know I can use boost::filesystem::path::operator/ to concatenate two paths together with the appropriate separator character. But I just want either / or \ . I also know I can use #ifdef _WIN32 , but I'd prefer that Boost.Filesystem tell me the appropriate separator character. EDIT: I want to use version 3 of the Boost.Filesystem API, as

Get relative path from two absolute paths

﹥>﹥吖頭↗ 提交于 2019-12-03 06:41:58
问题 I have two absolute filesystem paths (A and B), and I want to generate a third filesystem path that represents "A relative from B". Use case: Media player managing a playlist. User adds file to playlist. New file path added to playlist relative to playlist path . In the future, entire music directory (including playlist) moved elsewhere. All paths still valid because they are relative to the playlist. boost::filesystem appears to have complete to resolve relative ~ relative => absolute , but

Iterate over all files in a directory using BOOST_FOREACH

ⅰ亾dé卋堺 提交于 2019-12-03 04:59:33
Can you iterate over all files in a directory using boost::filesystem and BOOST_FOREACH? I tried path dirPath = ... int fileCount = 0; BOOST_FOREACH(const path& filePath, dirPath) if(is_regular_file(filePath)) ++fileCount; This code compiles, runs, but does not produce the desired result. nabulke You can iterate over files in a directory using BOOST_FOREACH like this: #include <boost/filesystem.hpp> #include <boost/foreach.hpp> namespace fs = boost::filesystem; fs::path targetDir("/tmp"); fs::directory_iterator it(targetDir), eod; BOOST_FOREACH(fs::path const &p, std::make_pair(it, eod)) { if

How to check for new files in the directory?

柔情痞子 提交于 2019-12-03 04:03:18
Given: filesystem::path toDir("./"); ptime oldTime; ptime now(second_clock::local_time()); How can I determine which files were created in the time period between oldTime and now ? The names of such "fresh" files should be streamed to cout . Update: Well based on given answer I made a small programm: #include <sstream> #include <stdio.h> #include <time.h> #include <boost/filesystem.hpp> #include <boost/thread.hpp> #include <boost/timer.hpp> #include <boost/date_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp> using namespace

Get relative path from two absolute paths

戏子无情 提交于 2019-12-02 20:13:26
I have two absolute filesystem paths (A and B), and I want to generate a third filesystem path that represents "A relative from B". Use case: Media player managing a playlist. User adds file to playlist. New file path added to playlist relative to playlist path . In the future, entire music directory (including playlist) moved elsewhere. All paths still valid because they are relative to the playlist. boost::filesystem appears to have complete to resolve relative ~ relative => absolute , but nothing to do this in reverse ( absolute ~ absolute => relative ). I want to do it with Boost paths. As

Why can't I change the 'last write time' of my newly created files?

我怕爱的太早我们不能终老 提交于 2019-12-02 11:59:49
First off, I'm using Visual Studio 2015's implementation of the Filesystem library from the upcoming C++17 standard, which is based on Boost::Filesystem. Basically, what I'm trying to do is save a file's timestamp (it's "last write time"), copy that file's contents into an archive along with said timestamp, then extract that file back out and use the saved timestamp to restore the correct "last write time". // Get the file's 'last write time' and convert it into a usable integer. __int64 timestamp = chrono::time_point_cast<chrono::seconds>(fs::last_write_time(src)).time_since_epoch().count();

How to get file permissions with c++ boost library?

老子叫甜甜 提交于 2019-12-01 18:09:35
I am working on a project to make a database of the files I have on current directory. And one of the details I want about my files is the file permissions that are set with chmod in ubuntu. (just a note: I will be needing the group and owner info too - like chown- and if you could let me know if boost can retrieve the ownership info too that'd be great.) I am using boost filesystem library and I have checked the documentation for numerous times but couldn't find how to get the permissions. In this page it shows that there's enum perms that has the file permission strings which doesn't show up

boost.filesystem create_directories throws std::bad_alloc

牧云@^-^@ 提交于 2019-12-01 18:04:33
I have a Visual Studio 2008 C++03 application using Boost 1.47.0 running in Windows XP SP3. The call boost::filesystem::create_directories( L"c:\\foo\\bar" ); throws a std::bad_alloc exception. In the output window, I see a debug heap message: "HEAP[test.exe]: Invalid allocation size - CDCDCDCE (exceeded 7ffdefff)" The callstack shows boost.filesystem creating a new locale and last visible line of code in the Microsoft standard library file xlocale line 309. msvcp90.dll!std::_Allocate<char>() + 0x17 bytes msvcp90.dll!std::allocator<char>::allocate() + 0xf bytes msvcp90.dll!std::basic_string