boost-filesystem

boost::filesystem::path for unicode file paths?

杀马特。学长 韩版系。学妹 提交于 2019-12-24 04:49:12
问题 Is there a way to use boost::filesystem::path with unicode file paths? In particular I'd like to use it with std::wstring instead of std::string. I'm working on the windows platform and I need to sometimes process a filepath that has a unicode char in it. 回答1: Looking at the header file, I see a wpath that's templated with std::wstring. 来源: https://stackoverflow.com/questions/394564/boostfilesystempath-for-unicode-file-paths

Why is boost::filesystem aborting instead of throwing an exception?

帅比萌擦擦* 提交于 2019-12-24 00:53:49
问题 I'm migrating some code from VS2010 (using boost 1.55) to VS 2015 (using boost 1.60). I end up with "Microsoft Visual C++ Runtime Library" reporting that abort() has been called while boost rties to throw an exception. However, I could get it throw other exceptions without any problem (and it used to work with VS2010/boost1.55): #include <boost/filesystem.hpp> #include <boost/filesystem/operations.hpp> #include <iostream> int main( int argc, char* argv[] ) { // Stepping to folder: try { boost

Having a map with paths how to compare tham to given path?

▼魔方 西西 提交于 2019-12-24 00:51:33
问题 We have map of boost path to string pairs like name:location (absolute location paths a la usr/myfolder/ ). We are given with some location a la usr/myfolder/mysubfolder/myfile . How to find which of maps location fit to given url most? Example we have a map like which we can resort if we need: service1:myfolder/ service2:myfolder/mysubfolder/ service3:myfolder/myothersubfolder/ service4:myfolder/mysubfolder/myfile We are given value myfolder/mysubfolder/myfile/blablabla/ (path). We want to

Boost.Filesystem create_directories mangles directory name

好久不见. 提交于 2019-12-23 20:49:36
问题 I am trying to make a directory using Boost.Filesystem (the directory can be provided by the user, so it may be a path with nested directories; all, some, or none of the directories in that path may exist to start). When I run the program, a directory is created, but it is not what I asked for; the string containing the path appears to be getting mangled. I never get the same result twice, but the name of the directory always starts with a colon. A minimal example: #include <iostream>

boost::filesystem::exists crashs

元气小坏坏 提交于 2019-12-23 19:19:49
问题 I'm using boost 1.52, when i'm trying to get a file from a network drive that i don't have permissions to read from. I get an exception, after using boost::filesystem::exists(fileName) Is there a work around nicer than just doing try, catch at every place? I have switched back for my old code for now: bool FileExists(const char* fileName) { struct stat my_stat; return (stat(fileName, &my_stat) == 0); } //boost Exists throws exception if there are no permissions for share folder bool

How to check if path leads to executable file?

六月ゝ 毕业季﹏ 提交于 2019-12-23 09:37:31
问题 I try to create some kind of file browser. I want to know if file under path is executable in a cross-platform way. How to do such thing with boost::filesystem? 回答1: Boost doesn't have stuff about permissions, because POSIX permissions are not "crossplatform". Use the platform-specific APIs at your disposal as required. Sorry! 回答2: You can try QT. It is cross-platform. You do not have to care about the operating system differences while dealing with files. What you mean by "executable" is

Traversing a directory with boost::filesystem without throwing exceptions

久未见 提交于 2019-12-22 06:44:45
问题 I have a path to the directory, and I want to traverse through all of its sub-directories, collecting files' pathes by the way. namespace fs = boost::filesystem; std::vector<fs::path> traverse_if_directory(fs::path& f) { std::vector<fs::path> result; if (fs::is_directory(f)) { for (fs::recursive_directory_iterator it(f), eit; it != eit; ++it) { if (!fs::is_directory(it->path())) { result.push_back(it->path()); } } } else { result.push_back(f); } return result; } Unfortunately, in the middle

Iterate over all files in a directory using BOOST_FOREACH

杀马特。学长 韩版系。学妹 提交于 2019-12-20 18:24:06
问题 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. 回答1: 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:

Boost::filesystem, std::sort: trouble retaining information on sort passes

不想你离开。 提交于 2019-12-20 05:16:54
问题 I'm trying to use std::sort on a data type that contains information read from a boost::filesystem::dictionary_iterator . It appears that as the sorting algorithm has done n comparisons, n being the number of files in the directory, that information gets lost and I end up segfaulting. Valgrind says I'm using uninitialized values and doing invalid reads. How can I change my File data type or algorithms so that the information is kept between passes? #include <iostream> #include <algorithm>

Get file's owner and group using boost

爱⌒轻易说出口 提交于 2019-12-19 21:35:57
问题 I want to get the owner and group from a file using boost::filesystem, but never found any way to do so. I can get the file's permissions, but as I don't know the file's owner this just doesn't mean anything. I found the posix fstat function, but again I'd like to use boost or another C++ library rather than C functions. 回答1: What you're asking to do is a Unix system call. But you don't want to call it? Why? What possible value could boost provide? It's not portability, as nothing outside of