12 #include <mrpt/config.h> 14 #ifdef MRPT_OS_WINDOWS 16 #include <sys/utime.h> 22 #include <sys/types.h> 36 #include <sys/types.h> 49 const string& path,
const unsigned long in_mask,
TFileInfoList& outList)
53 unsigned long mask = in_mask;
58 string searchPath(path);
59 if (searchPath.size())
60 if (searchPath[searchPath.size() - 1] !=
'\\' &&
61 searchPath[searchPath.size() - 1] !=
'/')
63 #ifdef MRPT_OS_WINDOWS 66 searchPath.push_back(
'/');
72 #ifdef MRPT_OS_WINDOWS 79 string searchPath_mask = searchPath +
string(
"*.*");
81 HANDLE h = FindFirstFileA(searchPath_mask.c_str(), &f);
82 if (h == INVALID_HANDLE_VALUE)
89 if ((
mask & f.dwFileAttributes) != 0)
100 (((
uint64_t)f.nFileSizeHigh) << 32);
104 if (stat(newEntry.
wholePath.c_str(), &statDat))
108 "Cannot get stat for file: '%s'",
112 newEntry.
modTime = statDat.st_mtime;
116 newEntry.
isDir = 0 != (statDat.st_mode & _S_IFDIR);
121 outList.push_back(newEntry);
123 }
while (FindNextFileA(h, &f));
135 DIR* dir = opendir(searchPath.c_str());
136 if (!dir)
THROW_EXCEPTION(
"Error starting exploration! (does path exist?)");
138 while ((ent = readdir(dir)) !=
nullptr)
140 if (strcmp(ent->d_name,
".") && strcmp(ent->d_name,
".."))
150 struct stat statDat, lstatDat;
151 if (stat(newEntry.
wholePath.c_str(), &statDat))
155 "Cannot get stat for file: '%s'",
159 newEntry.
modTime = statDat.st_mtime;
163 newEntry.
isDir = S_ISDIR(statDat.st_mode);
172 if (!lstat(newEntry.
wholePath.c_str(), &lstatDat))
174 newEntry.
isSymLink = S_ISLNK(lstatDat.st_mode);
180 outList.push_back(newEntry);
198 return a.wholePath <
b.wholePath;
204 return a.wholePath >
b.wholePath;
214 lstFiles.begin(), lstFiles.end(),
224 int i,
n = (int)lstFiles.size();
225 for (i =
n - 1; i >= 0; i--)
233 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.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
#define THROW_EXCEPTION(msg)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
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::deque< TFileInfo > TFileInfoList
The list type used in "explore".
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
GLsizei const GLchar ** string
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).
unsigned __int64 uint64_t
#define FILE_ATTRIB_DIRECTORY
GLuint const GLchar * name
GLubyte GLubyte GLubyte a
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)