void TraverseDir(const char* path, const char* relativePath) { DIR* dir = opendir(path); if (!dir) return; struct dirent entryBuf; struct dirent* entry = NULL; while (0 == readdir_r(dir, &entryBuf, &entry) && entry) { const char* entryName = entry->d_name; if (strcmp(entryName, ".") == 0 || strcmp(entryName, "..") == 0) continue; char entryPath[1024]; PathAppendEntry(entryPath, 1024, path, entryName); char relativeEntryPath[1024]; PathAppendEntry(relativeEntryPath, 1024, relativePath, entryName); struct stat statBuf; if (0 != lstat(entryPath, &statBuf)) continue; if (S_ISREG(statBuf.st_mode)) printf("%s | %s\n", entryPath, relativeEntryPath); else if (S_ISDIR(statBuf.st_mode)) TraverseDir(entryPath, relativeEntryPath); } closedir(dir); }
int main(int argc, char* argv[]) { if (argc < 2) { printf("Usage:\n"); printf(" %s [dir]\n", argv[0]); return 0; } const char* path = argv[1]; TraverseDir(path, ""); return 0; }
void TraverseDir(const boost::filesystem::path& root) { std::cout<<"+"<<root.string()<<std::endl; boost::filesystem::directory_iterator it(root), end; for (; it!=end; ++it) { if (boost::filesystem::is_directory(it->path())) { TraverseDir(it->path()); } else { FixFile(it->path()); } } }
void Run() { TraverseDir(m_srcDir); }