C語言目錄操作

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>

int main(void)
{
DIR dir = NULL;
struct dirent
ptr = (struct dirent )calloc(1, sizeof(struct dirent));
struct dirent
result = NULL;

dir = opendir("/root/tmp");
if (!dir) {
    printf ("opendir failed\n");
    return 1;
}

while ((readdir_r(dir, ptr, &result)==0) && (result != NULL)) {
    printf ("name:%s\n", result->d_name);
}
closedir(dir);

return 0;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章