C Program to Print names of all Files present in a Directory
C Program to Print names of all Files present in a Directory
dirent.h header file contains variables and functions related to directory streams.
#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:
testFile1.txt
testFile2.txt
testFile3.txt
testFile4.txt