06-29-04 08:16 AM
Howdy... Can anyone offer any suggestions on how to test whether a directory
is empty in a opendir/readdir/closedir scheme? I thought that I could
increment a counter for every thing that readdir finds, and if it gets to 2
( . and .. ) and then gets null, then that directory is empty... something
like that, maybe, but i'm having trouble with the implementation. Any
thoughts?
Guidance is, as always, appreciated.
void
printAllFileInfo( void ){
struct dirent *dstat;
DIR *dirp;
int i;
for(i=0;i<dlistlen;i++){
dirp = opendir( dlist[i] );
printf("\n%s:\n",dlist[i]);
while( dstat=readdir(dirp) ){ /* something something here....? */
if( strcmp(dstat->d_name,".") == 0 ||
strcmp(dstat->d_name,"..") == 0 )
continue;
/* pass the path and the filename to printOneFileInfo */
printOneFileInfo( dlist[i],dstat->d_name );
}
}
closedir(dirp);
}
[ Post a follow-up to this message ]
|