Skip to content

Instantly share code, notes, and snippets.

@alsamitech
Created August 7, 2021 07:11
Show Gist options
  • Save alsamitech/8b2d466ef92450e6891c85741d6409e1 to your computer and use it in GitHub Desktop.
Save alsamitech/8b2d466ef92450e6891c85741d6409e1 to your computer and use it in GitHub Desktop.
file_count- lists the amount of files in a directory
// file_count will add one to the count because zero is reserved for errors
size_t file_count(const char* dir_nm){
DIR* dir=opendir(dir_nm);
if(!dir)return 0;
struct dirent* entity=readdir(dir);
size_t count=0;
for(;readdir(dir);count++);
closedir(dir);
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment