Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <dirent.h>
- #include <sys/stat.h>
- int main ( int argc, char *argv[] )
- {
- DIR *pd; // Puntero a fichero directorio
- struct dirent *dirdatos; // Información sobre una entrada en el directorio
- struct stat statdatos; // Información sobre el fichero
- int numf; /* Nº de entradas en el directorio */
- int total; /* Tamaño total del los archivos */
- char nombreycamino [200]; /* Nombre completo directorio y archivo */
- if ( argc != 2 )
- {
- fprintf(stderr,"Nº de parámetros erróneo\n");
- fprintf(stderr,"Uso %s <Directorio> \n",argv[0]);
- return EXIT_FAILURE ;
- }
- pd = opendir ( argv[1] );
- if ( pd == NULL )
- {
- perror ( argv[1] );
- exit (1 );
- }
- numf = 0;
- total = 0;
- dirdatos = readdir ( pd );
- while ( dirdatos != NULL )
- {
- numf++;
- sprintf(nombreycamino,"%s\\%s",argv[1],dirdatos->d_name);
- // Información sobre el fichero
- if ( stat ( nombreycamino, & statdatos ) == 0)
- {
- printf ( "%2d> %-20.20s \t Tamaño:%10d \n",
- numf,
- dirdatos->d_name,
- statdatos.st_size );
- total += statdatos.st_size;
- }
- dirdatos = readdir (pd );
- }
- printf (" %d bytes en %d archivos.\n", total, numf );
- closedir ( pd );
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment