MCPcopy Create free account
hub / github.com/WinMerge/winmerge / LoadFiles

Function LoadFiles

Src/DirTravel.cpp:52–95  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

50 * @param [in] pattern Pattern for files to load, default is "*.*".
51 */
52void 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
98static inline int collate(const String &str1, const String &str2)

Callers 3

CleanupWMtempFunction · 0.85
LoadAndSortFilesFunction · 0.85
FindMostRecentCrashDumpFunction · 0.85

Calls 4

ConcatPathFunction · 0.85
IsWin7_OrGreaterFunction · 0.85
TFileClass · 0.85
tcsstrFunction · 0.85

Tested by

no test coverage detected