StudyingUnixInterface/4/fileDirectory/dirent.c

24 lines
375 B
C
Raw Normal View History

2020-12-07 04:17:01 +00:00
#include <dirent.h>
#include <stdio.h>
int main(void) {
DIR *pdir = opendir(".");
if(pdir == NULL) {
printf("opendir error\n");
return -1;
}
struct dirent *pdirent = NULL;
while((pdirent = readdir(pdir)) != NULL){
long index = telldir(pdir);
printf("%15s %18ld %lu\n", pdirent->d_name, index, pdirent->d_ino);
}
closedir(pdir);
return 0;
}