RWDirectoryIterator is a template class which represents a portable iterator over the content of a file system directory. RWDirectoryIterator has one specialization (const char*) suited for flat iteration (i.e. , no recursive iteration of directories) and one (RWCString) which is recursive.
Both specializations are: assignable, copy constructible, equality comparable.
RWDirectoryIterator<const char*> iter ("somedir"); // OK RWDirectoryIterator<const char*> iter1 (iter); // OK iter1 = iter; // OK bool b = iter == iter1; // OK
void ls (const char* s) { // Path RWCString path (s); std::cout << "Listing content of : " << s << std::endl; // Create the iterator RWDirectoryIterator<const char*> it (s); // Iterate until the iterator compares equal with the end // iterator (RWDirectoryIterator<const char*> ()) for(; it != RWDirectoryIterator<const char*> (); ++it) { std::cout << std::setw (40) << std::left << *it; RWCString filename (path); filename += PATH_SEPARATOR; filename += *it; // Print the filename std::cout << filename << "\n"; } std::cout << std::endl; }
void ls_R (const char* s, int depth = 0) { std::cout << "Recursively listing content of : " << s << " (depth: " << depth << ")\n"; // Create the iterator RWDirectoryIterator<RWCString> it (s, depth); // Iterate until iterator compares equal with end iterator // (RWDirectoryIterator<RWCString> ()) for (; it != RWDirectoryIterator<RWCString> (); ++it) { std::cout << std::setw (60) << std::left << *it; // Print the filename std::cout << *it << "\n"; } std::cout << std::endl; }
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.