c - stat function returns empty struct -


studentsdir = opendir(linevalues); while ((entry = readdir(studentsdir)) != null) {     stat(path, &dirdata);     if (s_isdir(dirdata.st_mode) && (entry->d_name[0] != '.')             && (entry->d_name[1] != '.')) { 

im searching in directory folders. problem stat returns dirdata empty values of folders

the code needs:

  #include <sys/types.h>   #include <sys/stat.h>   #include <unistd.h> 

the prototype function is:

  int stat(const char *path, struct stat *buf); 

so need:

struct stat dirdata; 

and *path variable needs actual path (can relative or absolute), file name, target file.

nothing in posted code indicates of above has been included in code.

and 'entry' pointer 'struct dirent' current file/directory name needs appended 'path' before stat() uses it.

'entry' needs checked assure not null before using it.

the struct dirent contains d_name[256] field contain name of current file (or directory) (but not whole path) each time code steps (sub) directory, (which posted code not doing) path needs have string d_name[] appended path string


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -