This script is generally quite similar to bigfiles.py. The only
important difference is how the files are sorted: in this
case, they are sorted in descending order by modification
time, that is, in reverse chronological order.
As with the bigfiles.py script, we create a class that inherits
from PathInfo, and define a different .__cmp__() method to change the sorting
behavior. Like bigfiles.py, we also redefine the .__str__() method to change the format used
to display each file's information.
We'll call the derived class OldInfo.
So, here's the overall flow for processing each directory tree named on the command line.
Instantiate a class called OldReport that holds all the information
needed to generate our report. The class constructor
takes the name of the director as an argument. It
walks the directory tree, makes each thing it finds
into an OldInfo object, and
then sorts them.
Use the .genFiles() method of
the BigReport object to
generate the OldInfo objects
in reverse chronological order, printing each one as it
is generated.
This part is identical to the corresponding section of bigfiles.py.
#!/usr/bin/env python #================================================================ # oldfiles.py: Show files in reverse chron. order by mod. time. # For documentation in "literate programming" style, see: # http://www.nmt.edu/help/lang/python/examples/pathinfo/ #---------------------------------------------------------------- SCRIPT_NAME = "oldfiles.py" EXTERNAL_VERSION = "1.1" #================================================================ # Imports #---------------------------------------------------------------- import sys, os import pathinfo