| |
---|
| | import sys |
---|
| | |
---|
| | # Version info |
---|
| | |
---|
| | VERSION = "$Id: tdir,v 1.62 2001/07/17 16:55:04 tundra Exp $" |
---|
| | VERSION = "$Id: tdir,v 1.63 2001/07/20 21:24:35 tundra Exp $" |
---|
| | |
---|
| | |
---|
| | # Booleans |
---|
| | |
---|
| |
---|
| | |
---|
| | RECURSE = FALSE # No recursion |
---|
| | SHOWDIR = TRUE # Show directories in listing |
---|
| | SHOWFILE = TRUE # Show files in listing |
---|
| | SORTBYEXT = TRUE # Sort file names by extension |
---|
| | |
---|
| | |
---|
| | def OrderByExtension(list): |
---|
| | ExtList = {} |
---|
| |
---|
| | if len(DirList) > 0: |
---|
| | DirList.sort() |
---|
| | OutputColumns(DirList, TRUE) |
---|
| | if len(FileList) > 0: |
---|
| | ExtList = OrderByExtension(FileList) |
---|
| | Ext = ExtList.keys() |
---|
| | Ext.sort() |
---|
| | for x in Ext: |
---|
| | FileList = ExtList[x] |
---|
| | if len(FileList) > 0: |
---|
| | FileList.sort() |
---|
| | if x == "": |
---|
| | sep = x |
---|
| | else: |
---|
| | sep = SEP |
---|
| | sys.stdout.write("{" + sep + x + "}\n") |
---|
| | OutputColumns(FileList, FALSE) |
---|
| | if SORTBYEXT: |
---|
| | ExtList = OrderByExtension(FileList) |
---|
| | Ext = ExtList.keys() |
---|
| | Ext.sort() |
---|
| | for x in Ext: |
---|
| | FileList = ExtList[x] |
---|
| | if len(FileList) > 0: |
---|
| | FileList.sort() |
---|
| | if x == "": |
---|
| | sep = x |
---|
| | else: |
---|
| | sep = SEP |
---|
| | sys.stdout.write("{" + sep + x + "}\n") |
---|
| | else: |
---|
| | FileList.sort() |
---|
| | OutputColumns(FileList, FALSE) |
---|
| | |
---|
| | |
---|
| | |
---|
| | def BuildFileList (args, dir, files): |
---|
| | DirList = [] |
---|
| |
---|
| | (" usage: tdir [-Rdfhtv] [-c #] [-s c] [-w #] [dir...] where,\n\n", ""), |
---|
| | ("-R", "Recurse down each named directory tree\n"), |
---|
| | ("-c #", "Column width\n"), |
---|
| | ("-d", "Do not display directories in output\n"), |
---|
| | ("-e", "Do not sort files by extension\n"), |
---|
| | ("-f", "Do not display files in output\n"), |
---|
| | ("-h", "Display this help information\n"), |
---|
| | ("-s c", "Separator character\n"), |
---|
| | ("-t", "Display only the directory tree - same as -Rdf\n"), |
---|
| |
---|
| | |
---|
| | # Program entry and command line processing |
---|
| | |
---|
| | try: |
---|
| | opts, args = getopt.getopt(sys.argv[1:], '-Rc:dfhs:tvw:') |
---|
| | opts, args = getopt.getopt(sys.argv[1:], '-Rc:edfhs:tvw:') |
---|
| | except getopt.GetoptError: |
---|
| | Usage() |
---|
| | sys.exit(2) |
---|
| | |
---|
| |
---|
| | if opt == "-c": |
---|
| | COLWIDTH = int(val) |
---|
| | if opt == "-d": |
---|
| | SHOWDIR = FALSE |
---|
| | if opt == "-e": |
---|
| | SORTBYEXT = FALSE |
---|
| | if opt == "-f": |
---|
| | SHOWFILE = FALSE |
---|
| | if opt == "-h": |
---|
| | Usage() |
---|
| |
---|
| | |