Sunday, 24 August 2014

Filled Under:

C Program to List Files in Directory

Share
This C Program lists files in directory.Here is source code of he C Program to list files in directory. The C program is successfully compiled and run on a Linux system as well as windows system. The program output is also shown below.
This C Program lists files in directory


C Program to List Files in Directory


#include <dirent.h>
#include <stdio.h>

 
int main(void)
{
    DIR *d;
struct dirent *dir;
    d = opendir(".");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
printf("%s\n", dir->d_name);
}
        closedir(d);
}
return(0);
}


Output

C Program to List Files in Directory