Thursday 1 June 2017

List all Files in Directory in C ~ GNIITHELP

Program to Print names of all Files present in a Directory

#include<stdio.h>
#include<dirent.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
File1.txt
File2.txt
File3.txt
File4.txt
File5.txt
File6.txt
File7.txt

No comments:

Post a Comment