import os
def myCmp(a, b):
'''Used for comparison of tuples based on first items.'''
return cmp(a[0], b[0])
# The list of backup directories. Here the four drives are simulated in
# four directories.
dirs = ['c:/tmp/backup1', 'c:/tmp/backup2', 'c:/tmp/backup3', 'c:/tmp/backup4']
# Build lst of tuples with bare name and full name. It assumes that all files
# in the directories are backup files. Otherwise, the list must be filtered
# first.
lst = []
for d in dirs:
lst.extend( (bare, os.path.join(d, bare)) for bare in os.listdir(d) )
# Now sort the list.
lst.sort(myCmp)
# Print the sorted bare names plus the full path to the file.
for bare, full in lst:
print bare, full
|