14 #include <sys/utime.h>    22 #include <sys/types.h>    31 #include <sys/types.h>    48     const string& path, 
const unsigned long in_mask, 
TFileInfoList& outList)
    52     unsigned long mask = in_mask;
    57     string searchPath(path);
    58     if (searchPath.size())
    59         if (searchPath[searchPath.size() - 1] != 
'\\' &&
    60             searchPath[searchPath.size() - 1] != 
'/')
    65             searchPath.push_back(
'/');
    78     string searchPath_mask = searchPath + string(
"*.*");
    80     HANDLE h = FindFirstFileA(searchPath_mask.c_str(), &f);
    81     if (h == INVALID_HANDLE_VALUE)
    88         if ((mask & f.dwFileAttributes) != 0)  
    91             newEntry.
name = string(f.cFileName);
    98             newEntry.
fileSize = ((uint64_t)f.nFileSizeLow) +
    99                                 (((uint64_t)f.nFileSizeHigh) << 32);
   103             if (stat(newEntry.
wholePath.c_str(), &statDat))
   107                     "Cannot get stat for file: '%s'",
   111             newEntry.
modTime = statDat.st_mtime;
   115             newEntry.
isDir = 0 != (statDat.st_mode & _S_IFDIR);
   120             outList.push_back(newEntry);
   122     } 
while (FindNextFileA(h, &f));
   134     DIR* 
dir = opendir(searchPath.c_str());
   137     while ((ent = readdir(
dir)) != 
nullptr)
   139         if (strcmp(ent->d_name, 
".") != 0 && strcmp(ent->d_name, 
"..") != 0)
   142             newEntry.
name = string(ent->d_name);
   152             if (stat(newEntry.
wholePath.c_str(), &statDat))
   156                     "Cannot get stat for file: '%s'",
   160             newEntry.
modTime = statDat.st_mtime;
   164             newEntry.
isDir = S_ISDIR(statDat.st_mode);
   170                 newEntry.
fileSize = (intmax_t)statDat.st_size;
   173                 if (!lstat(newEntry.
wholePath.c_str(), &lstatDat))
   175                     newEntry.
isSymLink = S_ISLNK(lstatDat.st_mode);
   181                 outList.push_back(newEntry);
   215         lstFiles.begin(), lstFiles.end(),
   225     int i, n = (int)lstFiles.size();
   226     for (i = n - 1; i >= 0; i--)
   234             lstFiles.erase(lstFiles.begin() + i);
 static void filterByExtension(TFileInfoList &lstFiles, const std::string &extension)
Remove from the list of files those whose extension does not coincide (without case) with the given o...
 
static void explore(const std::string &path, const unsigned long mask, TFileInfoList &outList)
The path of the directory to examine must be passed to this constructor, among the According to the f...
 
std::string wholePath
The whole file path. 
 
#define THROW_EXCEPTION(msg)
 
std::deque< TFileInfo > TFileInfoList
The list type used in "explore". 
 
bool cmpFileEntriesName_Desc(const CDirectoryExplorer::TFileInfo &a, const CDirectoryExplorer::TFileInfo &b)
 
This represents the information about each file. 
 
#define FILE_ATTRIB_ARCHIVE
 
time_t accessTime
Access and modification times. 
 
uint64_t fileSize
The size of the file in bytes. 
 
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename. 
 
static void sortByName(TFileInfoList &lstFiles, bool ascendingOrder=true)
Sort the file entries by name, in ascending or descending order. 
 
std::string name
The file name (without the whole path). 
 
#define FILE_ATTRIB_DIRECTORY
 
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
 
int _strcmpi(const char *str1, const char *str2) noexcept
An OS-independent version of strcmpi. 
 
bool cmpFileEntriesName_Asc(const CDirectoryExplorer::TFileInfo &a, const CDirectoryExplorer::TFileInfo &b)