#!/usr/bin/env python import sys usage = "./dir_expand.py " dirs = [] with(open(sys.argv[1])) as infile: for line in infile: line = line.strip() subdirs = line.split('/') if '*' in subdirs[0]: del subdirs[0] if subdirs[-1] != '': del subdirs[-1] for n in xrange(len(subdirs), 0, -1): tmpdir = '/'.join(subdirs[:n]) if not tmpdir.startswith('/'): tmpdir = '/' + tmpdir if not tmpdir.endswith('/'): tmpdir = tmpdir + '/' dirs.append(tmpdir) for line in sorted(list(set(dirs))): print line