#include #include #include #include #include #include #include #define FALSE 0 #define TRUE !FALSE extern int alphasort(); char pathname[MAXPATHLEN]; int main(int argc, char * argv[]) { int count,i; struct direct **files; int file_select(struct direct *entry); if (getwd(pathname) == NULL ){ printf("Error obteniendo ruta \n"); exit(0); } printf("Directorio Actual = %s\n",pathname); count = scandir(pathname, &files, file_select, alphasort); /* Si no se encuentran fichero, hacer items no seleccionables */ if(count <= 0){ printf("No hay ficheros en directorio\n"); exit(0); } printf("Cantidad de ficheros = %d\n",count); for (i=1;id_name); printf("\n"); /* flush buffer */ return 0; } int file_select(struct direct *entry) { if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) return (FALSE); else return (TRUE); }