Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/fantasmo/public_html/ash.wine/wp-content/plugins/jetpack/jetpack.php:1) in /home/fantasmo/public_html/ash.wine/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"id":292,"date":"2016-04-13T07:32:00","date_gmt":"2016-04-13T02:02:00","guid":{"rendered":"http:\/\/ash.wine\/?p=292"},"modified":"2016-11-18T15:27:54","modified_gmt":"2016-11-18T09:57:54","slug":"getting-all-files-in-a-specified-folder-using-boost","status":"publish","type":"post","link":"http:\/\/hacks.ash.wine\/getting-all-files-in-a-specified-folder-using-boost\/","title":{"rendered":"Getting all files in a specified folder using Boost."},"content":{"rendered":"
\n

\n<\/span><\/a>Getting all files in a specified folder using Boost.<\/h4>\n

Also check out how to get files of a specific type, and sorted results here!<\/a> <\/p>\n

\n
#include<\/span> <<\/span>boost\/filesystem.hpp><\/span><\/span>\n#include<\/span> <<\/span>boost\/range\/iterator_range.hpp><\/span><\/span>\n\n\/\/returns a list of all the files in a given folder.<\/span>\nstd::vector<boost::filesystem::directory_entry> GetAllFilesInFolder<\/span>(boost::filesystem::path folderPath)\n{\n    try<\/span>\n    {\n        if<\/span> (exists<\/span>(folderPath))    \/\/ does p actually exist?<\/span>\n        {\n            std::vector<boost::filesystem::directory_entry> files;\n\n            if<\/span> (is_regular_file<\/span>(folderPath))        \/\/ is p a regular file?<\/span>\n                cout << folderPath << \"<\/span> size is \"<\/span><\/span> << file_size<\/span>(folderPath) << '<\/span>\\n<\/span>'<\/span><\/span>;\n\n\n\n            else<\/span> if<\/span> (is_directory<\/span>(folderPath))      \/\/ is p a directory?<\/span>\n            {\n                cout << folderPath << \"<\/span> is a directory containing:\\n<\/span>\"<\/span><\/span>;\n                \/*<\/span>\n                copy(boost::filesystem::directory_iterator(folderPath), boost::filesystem::directory_iterator(),  \/\/ directory_iterator::value_type<\/span>\n                    ostream_iterator<boost::filesystem::directory_entry>(cout, \"\\n\"));  \/\/ is directory_entry, which is<\/span>\n                                                                     \/\/ converted to a path by the<\/span>\n                                                                     \/\/ path stream inserter<\/span>\n                *\/<\/span>\n                for<\/span> (auto<\/span>& entry : boost::make_iterator_range<\/span>(boost::filesystem::directory_iterator<\/span>(folderPath), {}))\n                {\n                    std::cout << entry << \"<\/span>\\n<\/span>\"<\/span><\/span>;\n                    files.push_back<\/span>(entry);\n                }\n                return<\/span> files;\n            }\n        }\n        else<\/span>\n        {\n            cout << folderPath << \"<\/span> does not exist\\n<\/span>\"<\/span><\/span>;\n        }\n\n    }\n\n    catch<\/span> (const<\/span> boost::filesystem::filesystem_error& ex)\n    {\n        cout << ex.what<\/span>() << '<\/span>\\n<\/span>'<\/span><\/span>;\n    }\n}<\/pre>\n<\/div>\n

\n<\/span><\/a>Usage:<\/h4>\n
\n
    vector<boost::filesystem::directory_entry> files = GetAllFilesInFolder(folder);<\/pre>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

Getting all files in a specified folder using Boost. Also check out how to get files of a specific type, and sorted results here! #include <boost\/filesystem.hpp> #include <boost\/range\/iterator_range.hpp> \/\/returns a list of all the files in a given folder. std::vector<boost::filesystem::directory_entry> GetAllFilesInFolder(boost::filesystem::path folderPath) { try { if (exists(folderPath)) \/\/ does p actually exist? { std::vector<boost::filesystem::directory_entry> files; […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[23,24],"_links":{"self":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/292"}],"collection":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/comments?post=292"}],"version-history":[{"count":1,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":293,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/posts\/292\/revisions\/293"}],"wp:attachment":[{"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/media?parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/categories?post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ash.wine\/wp-json\/wp\/v2\/tags?post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}