Aug 5, 2002 #1 waynejfoster Programmer Joined Aug 7, 2001 Messages 13 Location GB What function can I call to see if a directory is empty?
Aug 6, 2002 #2 keenanbr Programmer Joined Oct 3, 2001 Messages 469 Location IE struct dirent *dirp; DIR *dp; #include <stdio.h> #include <dirent.h> int no_files = 0; if ((dp ==opendir("youdirectoryname" == (DIR *) NULL) ..... error cant open dir else { while (readdir(dp)) != (DIR *) NULL) if (strcmp(dirp->d_name, "." == 0 || strcmp(dirp->d_name, ".." == 0) continue; no_files++; } closedir(dp); printf(there are %d files \n", no_files); Upvote 0 Downvote
struct dirent *dirp; DIR *dp; #include <stdio.h> #include <dirent.h> int no_files = 0; if ((dp ==opendir("youdirectoryname" == (DIR *) NULL) ..... error cant open dir else { while (readdir(dp)) != (DIR *) NULL) if (strcmp(dirp->d_name, "." == 0 || strcmp(dirp->d_name, ".." == 0) continue; no_files++; } closedir(dp); printf(there are %d files \n", no_files);