You always call stat
for the directory itself.
This ...:
while ((direntp=readdir(dirp)) != NULL) {
stat(ruta, &estructura);
...
}
... should be something like:
while ((direntp=readdir(dirp)) != NULL) {
char pathname[1024];
sprintf( pathname, "%s/%s", ruta, direntp->d_name );
stat( pathname, &estructura );
...
}