How to view all files in the current directory
/*
Example: display the names of all files in the current directory using C language
*/
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char const *argv[]) {
DIR *d;
struct dirent *dir;
d = opendir(".");
if (d) {
while ((dir = readdir(d)) != NULL) {
printf("%s\n", dir->d_name);
}
closedir(d);
}
return(0);
}Source:www.lautturi.comexample of output:
. .. bin hello.cbp hello.cscope_file_list hello.depend hello.layout main.c obj test.txt