Implementing a directory listing on Linux source code

This snippet submitted by Joshith on 2010-09-28. It has been viewed 4784 times.
Rating of 6.3 with 12 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

Add a snippet!