Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
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());
         }
     }
 }
Ejemplo n.º 4
0
 void Run()
 {
     TraverseDir(m_srcDir);
 }