The
ScanDir library provides access to file and directory information using standard C
idioms. file.h contains the class interface, and filecompare.h adds some functors for use with STL algorithms. Tapestry functions are used internally, which in turn call standard Unix libraries; however, the former are being ported to a variety of platforms, any of which will then work with ScanDir.
A File object holds the structure of the directory passed to its constructor, and allows traversal via iterators. Once constructed, you can call the following functions:
* File::iterator begin()
* File::iterator end()
These iterators implement the STL conventions for a mutable, random access iterator. Thus, any STL operation that can be performed on an iterator of these types will be valid operations on File.
File is also the object that contains the accessor functions that may be called on each entry (this is, any dereferenced object in the range [begin, end)). A summary of these is given below:
* bool IsDir() -- returns whether or not the given entry is a directory on the filesystem
* string Name() -- returns the name of the entry
* string Path() -- returns the canonical path of the entry
* int Size() -- returns the size of the entry in bytes
* Date GetDate() -- returns the date of the last modification (Tapestry date.h required)
* ClockTime GetTime() -- returns the time of the last modification (Tapestry clockt.h required)
In filecompare.h, three functors are provided that will compare two File entries by name, size, or time/date. They can be passed to STL algorithms in the normal fashion.
An example of using the library is found in usefile.cpp. This program emulates a "light" version of Unix's ls, supporting the -l and -t options and the ability to scan a given directory. The implementation is ugly, but should provide a good example of what the File library is capable of. In other words, feel free to copy the functionality if not the style.
In case you're rightfully scared to look at this program, here's the ultra-simple version:
File f(myDirectory);
File::iterator it = f.begin()
while (it != f.end())
cout << it->Name() << endl;
That prints out the name of the files in myDirectory. I think.
Further documentation on the compilation and use of the usefile driver program, as well as of the dotest/runtest driver programs for the driver program, is given in the README.
Back to ScanDir
There are no comments on this page. [Add comment]