Skip to content

Instantly share code, notes, and snippets.

@dattaz
Created February 19, 2017 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dattaz/a7d9b1932b18e3a5378e0c1361d7ffaf to your computer and use it in GitHub Desktop.
Save dattaz/a7d9b1932b18e3a5378e0c1361d7ffaf to your computer and use it in GitHub Desktop.
Count number of file in your current path
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
int main (void){
DIR *dp;
dp = opendir ("./");
int i=0;
if (dp != NULL){
while (readdir (dp)){
i++;
}
closedir (dp);
printf("%d\n",i-2);
}
else{
perror ("Couldn't open the directory");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment