Last active
February 21, 2017 06:57
-
-
Save bzdgn/5d1bbe7974d81139b47c02aae209302d to your computer and use it in GitHub Desktop.
Prints The Working Directory Contents With Inode Number, File Type number and File Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <dirent.h> | |
#include <sys/types.h> | |
printInfo(struct dirent *info) | |
{ | |
if(info == NULL) { | |
return; | |
} | |
printf("\tInode : %ld\n", info->d_ino); | |
printf("\tFile Type: %d\n" , info->d_type); | |
printf("\tFile Name: %s\n" , info->d_name); | |
printf("\t\n"); | |
} | |
printDirectory(const char * path) | |
{ | |
DIR *dir; | |
struct dirent *info; | |
dir = opendir(path); | |
while( (info = readdir(dir)) != NULL) { | |
printInfo(info); | |
} | |
printf("End of directory\n"); | |
closedir(dir); | |
} | |
int main() | |
{ | |
printDirectory("."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Usage;