Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active February 21, 2017 06:57
Show Gist options
  • Save bzdgn/5d1bbe7974d81139b47c02aae209302d to your computer and use it in GitHub Desktop.
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
#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;
}
@bzdgn
Copy link
Author

bzdgn commented Feb 21, 2017

Sample Usage;

readd_c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment