1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00
vcmi/lib/CFileUtility.cpp
Michał W. Urbańczyk 580c4e4c9b ERM is now a separate project, linking to ./Scripting/ERM.dll and consisting all ERM* files from ./lib.
Little changes around handling ERM. New class in lib: CFileUtility, so the code for scanning files with given extension is not duplicated.
2011-06-20 11:41:04 +00:00

46 lines
1.1 KiB
C++

#define VCMI_DLL
#include "CFileUtility.h"
#include <boost/filesystem.hpp> // includes all needed Boost.Filesystem declarations
#include <boost/algorithm/string/predicate.hpp>
namespace fs = boost::filesystem;
CFileUtility::CFileUtility(void)
{
}
CFileUtility::~CFileUtility(void)
{
}
void CFileUtility::getFilesWithExt(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext)
{
if(!fs::exists(dirname))
{
tlog1 << "Cannot find " << dirname << " directory!\n";
}
fs::path tie(dirname);
fs::directory_iterator end_iter;
for ( fs::directory_iterator file (tie); file!=end_iter; ++file )
{
if(fs::is_regular_file(file->status())
&& boost::ends_with(file->path().filename(), ext))
{
std::time_t date = 0;
try
{
date = fs::last_write_time(file->path());
out.resize(out.size()+1);
out.back().date = date;
out.back().name = file->path().string();
}
catch(...)
{
tlog2 << "\t\tWarning: very corrupted file: " << file->path().string() << std::endl;
}
}
}
}