The following function prints the name and loid of each entry in the directory given by the pathname argument.
int count(const char *pathname)
{
DirEntry entry;
int count = 0;
// Open a scan over the pool given by "pathname."
DirScan scan(pathname);
// Make sure the scan was successfully opened.
if(scan != RCOK){
cout << "Error scanning directory " << pathname << ": "
<< rc << endl;
return 0;
}
// Scan until end-of-scan or an error is encountered.
for(count = 0; scan.next(&entry) == RCOK; ++count);
cout << path << " has " << count << " objects." << endl;
// Check for errors.
if(scan.rc().err_num() != OC_EndOfScan){
cout << "Error scanning directory " << pathname << ": "
<< rc << endl;
return 0;
}
// The destructor will close the scan object.
return count;
}