sorting pathnames by basename

Michael O'Donnell mod+gnhlug at std.com
Tue Aug 20 08:03:32 EDT 2002


Erik Price wrote:
>#!/usr/bin/python
>#
># basenamesort.py
>#
># Unix-style filter that sorts a newline-separated
># list of files by the file basename
>#
># Example usage:  cat files.txt | basenamesort.py
>        
>import sys
>import os
>        
>tempDict = {}
> 
>for line in sys.stdin.xreadlines():
>  tempDict[os.path.basename(line)] = line.rstrip()
> 
>sorted = tempDict.keys()
>        
>sorted.sort()
>
>for key in sorted:
>  print tempDict[key]



Wow.  That doesn't suck.  Thanks!




More information about the gnhlug-discuss mailing list