The overall flow of this script is similar to that for
bigfiles.py. If any directory paths
are given on the command line, a report is printed for each
one. If there are no command line arguments, one report is
printed for the current directory “.”.
As the os.path.walk() function visits every
directory and file in a tree, the visitor function finds
the soft links, and accumulates a list of PathInfo instances
for each one. Those instances are sorted by path name
(which is the default ordering for PathInfo instances), then
the entries in the sorted list are displayed in the body of
the report.
The script starts with the usual “pound bang line”, a comment pointing to this documentation, and constants defining the script name and external version number.
#!/usr/bin/env python
#================================================================
# softlinks.py: Script to find all soft links a directory tree.
# For documentation in "literate programming" style, see:
# http://www.nmt.edu/tcc/help/lang/python/examples/pathinfo/
#----------------------------------------------------------------
SCRIPT_NAME = "softlinks.py"
EXTERNAL_VERSION = "1.0"
Next we import the usual modules for the system and
operating system interfaces, and of course the PathInfo
class.
#================================================================ # Imports #---------------------------------------------------------------- import sys, os import pathinfo