Implementing a directory listing on Linux source codeThis snippet submitted by Joshith on 2010-09-28. It has been viewed 16283 times.Rating of 5.1 with 89 votes //DIR #include<sys/types.h> #include<dirent.h> #include<stdio.h> #include<string.h> int main(int argc,char *argv []) { DIR *dp; char st[100]; struct dirent *ep; if(argc<2) { printf("\nPlease specify the file path\n"); gets(st); dp=opendir(st); } else dp=opendir(argv[1]); while((ep=readdir(dp))) puts(ep->d_name); closedir(dp); return 0; } More C and C++ source code snippets |