25 #if PLATFORM_IS_LINUX || PLATFORM_IS_APPLE 26 #include <sys/statvfs.h> 39 return (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode));
45 size_t startSize = files.size();
46 std::regex* rePtr =
NULL;
48 if (regexPattern.length() != 0)
50 re = std::regex(regexPattern, std::regex::icase);
62 static char longFileName[
_MAX_LFN + 1];
63 info.
lfname = longFileName;
64 info.
lfsize =
sizeof(longFileName);
68 result =
f_opendir(&dir, directory.c_str());
69 if (result ==
FR_OK) {
79 file_name = info.
fname;
81 std::string full_file_name = directory +
"/" + file_name;
84 if (file_name[0] ==
'.' || (rePtr !=
NULL && !regex_search(full_file_name, re)))
95 files.push_back(full_file_name);
101 #elif PLATFORM_IS_WINDOWS 104 WIN32_FIND_DATAA file_data;
105 if ((dir = FindFirstFileA((directory +
"/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE)
111 std::string file_name = file_data.cFileName;
112 std::string full_file_name = directory +
"/" + file_name;
113 if (file_name[0] ==
'.' || (rePtr !=
NULL && !regex_search(full_file_name, re)))
117 else if ((file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
125 files.push_back(full_file_name);
126 }
while (FindNextFileA(dir, &file_data));
133 DIR* dir = opendir(directory.c_str());
139 while ((ent = readdir(dir)) !=
NULL) {
140 const std::string file_name = ent->d_name;
141 const std::string full_file_name = directory +
"/" + file_name;
144 if (file_name[0] ==
'.' || stat(full_file_name.c_str(), &st) == -1 ||
145 (rePtr !=
NULL && !regex_search(full_file_name, re))) {
148 else if ((st.st_mode & S_IFDIR) != 0) {
155 files.push_back(full_file_name);
161 return (files.size() != startSize);
171 #if PLATFORM_IS_EVB_2 174 return (std::remove(fullFilePath.c_str()) == 0);
182 #if PLATFORM_IS_EVB_2 185 #elif PLATFORM_IS_WINDOWS 188 WIN32_FIND_DATAA file_data;
189 if ((dir = FindFirstFileA((directory +
"/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE)
195 const std::string file_name = file_data.cFileName;
196 const std::string full_file_name = directory +
"/" + file_name;
197 const bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
198 if (file_name[0] ==
'.')
202 else if (is_directory)
210 std::remove(full_file_name.c_str());
211 }
while (FindNextFileA(dir, &file_data));
220 if ((dir = opendir(directory.c_str())) ==
NULL) {
224 while ((ent = readdir(dir)) !=
NULL) {
225 const std::string file_name = ent->d_name;
226 const std::string full_file_name = directory +
"/" + file_name;
229 if (file_name[0] ==
'.' || stat(full_file_name.c_str(), &st) == -1) {
231 }
else if ((st.st_mode & S_IFDIR) != 0) {
237 std::remove(full_file_name.c_str());
243 _RMDIR(directory.c_str());
248 std::vector<file_info_t> files;
259 bool sortByDate,
bool recursive)
261 #if PLATFORM_IS_EVB_2 262 static_assert((
sizeof(time_t) >= 2 *
sizeof(
WORD)),
"time_t must be at least 2* DWORD, since we store the FatFs date/time (DWORD) in a time_t here.");
265 std::vector<std::string> fileNames;
267 uint64_t spaceUsed = 0;
268 for (
unsigned int i = 0; i < fileNames.size(); i++)
271 info.
name = fileNames[i];
272 #if PLATFORM_IS_EVB_2 280 stat(info.
name.c_str(), &st);
281 info.
size = st.st_size;
284 files.push_back(info);
285 spaceUsed += info.
size;
302 sort(files.begin(), files.end(), customSortDate);
311 sort(files.begin(), files.end(), customSortName);
319 #if PLATFORM_IS_EVB_2 333 sector_size = fs->ssize;
336 return free_clusters * fs->
csize * sector_size;
338 #elif PLATFORM_IS_WINDOWS 340 ULARGE_INTEGER space;
341 memset(&space, 0,
sizeof(space));
342 char fullPath[MAX_PATH];
343 GetFullPathNameA(directory.c_str(), MAX_PATH, fullPath,
NULL);
344 bool created = (
_MKDIR(fullPath) == 0);
345 GetDiskFreeSpaceExA(fullPath, &space,
NULL,
NULL);
350 return (uint64_t)space.QuadPart;
355 memset(&stat, 0,
sizeof(stat));
356 char fullPath[PATH_MAX];
357 if (realpath(directory.c_str(), fullPath) ==
NULL)
361 bool created = (
_MKDIR(fullPath) == 0);
362 statvfs(fullPath, &stat);
367 return (uint64_t)stat.f_bsize * (uint64_t)stat.f_bavail;
375 size_t lastSepIndex = path.find_last_of(
"\\/");
376 if (lastSepIndex != std::string::npos)
378 return path.substr(lastSepIndex + 1);
385 #if PLATFORM_IS_EVB_2 389 info.
ftime =
static_cast<WORD>(datetime);
394 return (
_UTIME(path.c_str(), &buf) == 0);
time_t lastModificationDate
bool PathIsDir(const std::string &path)
uint32_t get_fattime(void)
Current time returned is packed into a DWORD value.
FRESULT f_utime(const TCHAR *path, const FILINFO *fno)
uint64_t GetDirectorySpaceAvailable(const std::string &directory)
bool GetAllFilesInDirectory(const std::string &directory, bool recursive, const std::string ®exPattern, std::vector< std::string > &files)
bool DeleteFile(const std::string &fullFilePath)
FRESULT f_unlink(const TCHAR *path)
FRESULT f_getfree(const TCHAR *path, DWORD *nclst, FATFS **fatfs)
std::string GetFileName(const std::string &path)
FRESULT f_readdir(DIR *dj, FILINFO *fno)
uint64_t GetDirectorySpaceUsed(const std::string &directory, bool recursive)
FRESULT f_stat(const TCHAR *path, FILINFO *fno)
void DeleteDirectory(const std::string &directory, bool recursive)
FRESULT f_opendir(DIR *dj, const TCHAR *path)
bool TouchFile(const std::string &path)