You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 resultsvoidGetFilesOfTypeInDirectory(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 functionstd::sort(list.begin(), list.end(), PathSort);
}
boolPathSort(const boost::filesystem::path &first, const boost::filesystem::path &second)
{
return first.filename().string() < second.filename().string();
}
I do not see a license listed for your codes. Would it be possible to add one or point me to where it is so I know the restrictions on using the provided code?
I do not see a license listed for your codes. Would it be possible to add one or point me to where it is so I know the restrictions on using the provided code?
Honestly, I haven't touched C++ in 4 years, but this looks like fairly standard code.
Google search for the method name "GetFilesOfTypeInDirectory" yields only this gist as a search result, all the functions being used return results from Boost's documentation.
Seems like it depends on Boost and the standard library, but feel free to do whatever you desire to with these 9 lines of code, consider it a WTFPL license for this bit.
I do not see a license listed for your codes. Would it be possible to add one or point me to where it is so I know the restrictions on using the provided code?
Thank you!