return -1;
}
list <string> files; //read names into st ring list, "files"
while( dirent * dp = readdir(dirp)) {
cout << dp->d_name << endl;
files.push_back(dp->d_name);
}
closedir(dirp); //close DIR asap
cout << root << ":" << endl; //emit header
cout <<"total " << (sizeof(files) / 1024)<< endl; //output the size of the file.
//lstat and report on each file, creating list of subdirectories
list <string> hardSubdirectories ;
files.sort();
each(files) {
string filename = root + "/" + *it;
struct stat st;
if (lstat(filename.c_str() ,&st)) continue;
//my program goes into
// an infinite loop after this command ****
// it looks like ././././././././././././././././././././
//if this file is a hard-linked subdirectories, add it to list
if( S_ISDIR ( st.st_mode) && ! S_ISLNK( st.st_mode) ){
hardSubdirectories.push_back(filename);
}
}
//Recurse through the hard_linked subdirectories.
each(hardSubdirectories) {
cout << endl;
walk(*it);
}