CPS 108: Scandir


You are to implement a wrapper around the old C library function scandir as a  C++ library that provides the same functionality, but with a spiffier object-oriented interface.  In other words, you should provide a set of classes that allows users to access the contents of a directory in a variety of ways.

Specification

The C-library function scandir is described in the Solaris man page (or type man scandir). This function is not available on all Unix platforms (note the BSD compatibility in the Solaris man pages).

You must design and implement classes whose use is similar to the scandir function from a user's perspective, but for a user versed in C++ rather than C. This means that you should use STL vectors instead of C-style arrays, strings instead of C-style strings (0 terminated character arrays), etc. You may implement several classes as part of the implementation of the main class whose interface the user sees as providing equivalent (or better) functionality than scandir.  Additionally, you must supply default classes/functions not only for lexicographic ordering of directory entries (see alphasort in the scandir man pages), but also ordering by date-last-modified and by size of entry.

Just as the scandir function supports filtering of file/directory names, your classes must also support filtering. At a minimum, a user of your library must be able to filter names using strings. For extra credit, you can use regular expressions; information about using regular expressions is here.

You must supply online HTML documentation (like man pages) that describes how to use your classes and shows some example code.

Example Code

These files are accessible on the acpub system in ~rcduvall/cps108/code/scandir You are welcome to use/modify/ignore the following code:

Implementation

Rather than use raw C-library system functions readdir, stat, and realpath, you should use the DirEntry and DirStream classes accessible above. Since these classes may be ported to other platforms (e.g., they are available now on Wintel machines) your class/module will be more portable than the Unix scandir command.

You must supply a const iterator that provide access to the entries (in sorted order) that are compiled when a scandir object is "loaded" with directory and file information. You can supply these iterators using makeIterator functions or you can use scandir class typedefs as is done with STL.

You must supply static or shared/dynamic libraries for your scanddir classes so that users can include your header file, link the library, and use your scandir classes. You must supply a Makefile that will compile both libscandir.a or libscandir.so (static and shared libraries, respectively). Information on creating libraries is here.


Comments?