Hello,
I have a program where I am testing to see whether something is a file or directroy using S_ISDIR. Here is my code:
My output:Code:void Find::get_dir() { struct dirent *ep; struct stat statbuf; DIR *dp; dp = opendir(path.c_str()); if(dp == NULL) throw domain_error("ERROR - " + path + " is not a valid path."); while((ep = readdir(dp))) { stat(ep->d_name, &statbuf); if(S_ISDIR(statbuf.st_mode)) dir.push_back(ep->d_name); } closedir(dp); sort(dir.begin(), dir.end()); typedef vector<string>::const_iterator iter; for(iter i = dir.begin(); i != dir.end(); i++) cout << *i << endl; }
Are files and directories both considered file types? I want to weed out files like .dbus and .autofsck and only keep directories. Any ideas?.
..
.autofsck
.dbus
bin
boot
dev
home
lib
lost+found
media
mnt
opt
proc
sbin
selinux
srv
sys
tmp
usr
var



LinkBack URL
About LinkBacks


