Efficiently Traverse Directory Tree with opendir(), readdir() and closedir()

后端 未结 5 1102
[愿得一人]
[愿得一人] 2020-12-30 02:35

The C routines opendir(), readdir() and closedir() provide a way for me to traverse a directory structure. However, each dirent structure returned by readdir() does not seem

5条回答
  •  长情又很酷
    2020-12-30 02:39

    Have you tried ftw() aka File Tree Walk ?

    Snippit from man 3 ftw:

    int ftw(const char *dir, int (*fn)(const char *file, const struct stat *sb, int flag), int nopenfd);

    ftw() walks through the directory tree starting from the indicated directory dir. For each found entry in the tree, it calls fn() with the full pathname of the entry, a pointer to the stat(2) structure for the entry and an int flag

提交回复
热议问题