| 111 | } |
| 112 | |
| 113 | void ListFilesInDirRecursive(const std::string &Dir, long *Epoch, |
| 114 | std::vector<std::string> *V, bool TopDir) { |
| 115 | auto E = GetEpoch(Dir); |
| 116 | if (Epoch) |
| 117 | if (E && *Epoch >= E) return; |
| 118 | |
| 119 | std::string Path(Dir); |
| 120 | assert(!Path.empty()); |
| 121 | if (Path.back() != '\\') |
| 122 | Path.push_back('\\'); |
| 123 | Path.push_back('*'); |
| 124 | |
| 125 | // Get the first directory entry. |
| 126 | WIN32_FIND_DATAA FindInfo; |
| 127 | HANDLE FindHandle(FindFirstFileA(Path.c_str(), &FindInfo)); |
| 128 | if (FindHandle == INVALID_HANDLE_VALUE) |
| 129 | { |
| 130 | if (GetLastError() == ERROR_FILE_NOT_FOUND) |
| 131 | return; |
| 132 | Printf("No such file or directory: %s; exiting\n", Dir.c_str()); |
| 133 | exit(1); |
| 134 | } |
| 135 | |
| 136 | do { |
| 137 | std::string FileName = DirPlusFile(Dir, FindInfo.cFileName); |
| 138 | |
| 139 | if (FindInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 140 | size_t FilenameLen = strlen(FindInfo.cFileName); |
| 141 | if ((FilenameLen == 1 && FindInfo.cFileName[0] == '.') || |
| 142 | (FilenameLen == 2 && FindInfo.cFileName[0] == '.' && |
| 143 | FindInfo.cFileName[1] == '.')) |
| 144 | continue; |
| 145 | |
| 146 | ListFilesInDirRecursive(FileName, Epoch, V, false); |
| 147 | } |
| 148 | else if (IsFile(FileName, FindInfo.dwFileAttributes)) |
| 149 | V->push_back(FileName); |
| 150 | } while (FindNextFileA(FindHandle, &FindInfo)); |
| 151 | |
| 152 | DWORD LastError = GetLastError(); |
| 153 | if (LastError != ERROR_NO_MORE_FILES) |
| 154 | Printf("FindNextFileA failed (Error code: %lu).\n", LastError); |
| 155 | |
| 156 | FindClose(FindHandle); |
| 157 | |
| 158 | if (Epoch && TopDir) |
| 159 | *Epoch = E; |
| 160 | } |
| 161 | |
| 162 | void IterateDirRecursive(const std::string &Dir, |
| 163 | void (*DirPreCallback)(const std::string &Dir), |