* @brief Find file and sub-folder names from given folder. * This function saves all file and sub-folder names in given folder to arrays. * We use 64-bit version of stat() to get times since find doesn't return * valid times for very old files (around year 1970). Even stat() seems to * give negative time values but we can live with that. Those around 1970 * times can happen when file is creat
| 50 | * @param [in] pattern Pattern for files to load, default is "*.*". |
| 51 | */ |
| 52 | void LoadFiles(const String& sDir, DirItemArray* dirs, DirItemArray* files, const String& pattern) |
| 53 | { |
| 54 | boost::flyweight<String> dir(sDir); |
| 55 | String sPattern = paths::ConcatPath(sDir, pattern); |
| 56 | |
| 57 | WIN32_FIND_DATA ff; |
| 58 | HANDLE h; |
| 59 | if (IsWin7_OrGreater()) // (also 'Windows Server 2008 R2' and greater) for FindExInfoBasic and FIND_FIRST_EX_LARGE_FETCH |
| 60 | h = FindFirstFileEx(TFile(sPattern).wpath().c_str(), FindExInfoBasic, &ff, FindExSearchNameMatch, nullptr, FIND_FIRST_EX_LARGE_FETCH); |
| 61 | else |
| 62 | h = FindFirstFile(TFile(sPattern).wpath().c_str(), &ff); |
| 63 | if (h != INVALID_HANDLE_VALUE) |
| 64 | { |
| 65 | do |
| 66 | { |
| 67 | bool bIsDirectory = (ff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0; |
| 68 | if (bIsDirectory && tc::tcsstr(_T(".."), ff.cFileName)) |
| 69 | continue; |
| 70 | |
| 71 | DirItem ent; |
| 72 | |
| 73 | // Save filetimes as seconds since January 1, 1970 |
| 74 | // Note that times can be < 0 if they are around that 1970.. |
| 75 | // Anyway that is not sensible case for normal files so we can |
| 76 | // just use zero for their time. |
| 77 | ent.ctime = Timestamp::fromFileTimeNP(ff.ftCreationTime.dwLowDateTime, ff.ftCreationTime.dwHighDateTime); |
| 78 | ent.mtime = Timestamp::fromFileTimeNP(ff.ftLastWriteTime.dwLowDateTime, ff.ftLastWriteTime.dwHighDateTime); |
| 79 | |
| 80 | if (ff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 81 | ent.size = DirItem::FILE_SIZE_NONE; // No size for directories |
| 82 | else |
| 83 | { |
| 84 | ent.size = ((int64_t)ff.nFileSizeHigh << 32) + ff.nFileSizeLow; |
| 85 | } |
| 86 | |
| 87 | ent.path = dir; |
| 88 | ent.filename = ff.cFileName; |
| 89 | ent.flags.attributes = ff.dwFileAttributes; |
| 90 | |
| 91 | (bIsDirectory ? dirs : files)->push_back(ent); |
| 92 | } while (FindNextFile(h, &ff)); |
| 93 | FindClose(h); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static inline int collate(const String &str1, const String &str2) |
no test coverage detected