Question

I have a problem with this function :

dirp = opendir(ruta);

    if (dirp != NULL){   
        while ((direntp=readdir(dirp)) != NULL) {       
            stat(ruta, &estructura);

Sorry for my English ... i hope that you can understand me

-------------------------------------------------------------------------------------

Thanks, the funcion works perfectly!

I changed my code for this:

while ((direntp=readdir(dirp)) != NULL) {       
                sprintf( cwd, "%s/%s", ruta, direntp->d_name );
                    stat(cwd, &estructura );

Thanks for your help and sorry to write here but i cant write a comment in 7 h. Thanks!!!!!!!

thank you

Was it helpful?

Solution 2

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 );

    ...
}

OTHER TIPS

It's because you get the information from stat for the directory, the one you pass to opendir.

You have to use that directory as a base, and then append the filenames you get from readdir.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top