Skip to content

Instantly share code, notes, and snippets.

@oscarsaleta
Created June 7, 2016 09:29
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 oscarsaleta/7412a6e098342869fb04c8a40bb225b1 to your computer and use it in GitHub Desktop.
Save oscarsaleta/7412a6e098342869fb04c8a40bb225b1 to your computer and use it in GitHub Desktop.
Compta fitxers d'una carpeta que continguin una paraula al nom, i retorna un percentatge basat en el total de fitxers que esperaries obtenir al final de l'execució que estiguis fent (serveix per comptar fitxers en carpetes amb cents de mils d'arxius)
#include <stdio.h>
#include <dirent.h>
#include <string.h>
int main(int argc, char *argv[]) {
DIR *dir;
struct dirent *ent;
long count = 0;
int maxfiles = atoi(argv[2]);
dir = opendir(argv[1]);
while((ent = readdir(dir))){
if(strstr(ent->d_name,argv[3])!=NULL)
++count;
}
closedir(dir);
printf("%s contains %ld *stdout files\n", argv[1], count);
printf("\twhich means a progress of %g\%\n",count/(double)(maxfiles)*100);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment