common/tools/listdir.py
changeset 966 e06b37cce80d
parent 351 a4c764727769
child 996 64899060ea4d
equal deleted inserted replaced
965:3eaa6b94ec68 966:e06b37cce80d
    24   directory = sys.argv[1]
    24   directory = sys.argv[1]
    25   exclude_dirs = []
    25   exclude_dirs = []
    26   if(len(sys.argv)>2):
    26   if(len(sys.argv)>2):
    27     x_dirs = string.lower(sys.argv[2])
    27     x_dirs = string.lower(sys.argv[2])
    28     exclude_dirs = re.split(',', x_dirs)
    28     exclude_dirs = re.split(',', x_dirs)
    29   scandir(directory, exclude_dirs)
    29   scandir(directory, exclude_dirs,directory)
    30 
    30 
    31 def scandir(top, exclude_dirs):
    31 def scandir(top, exclude_dirs,directory):
    32     fixpath = re.compile('\\\\')    
    32     fixpath = re.compile('\\\\')    
    33     fixroot = re.compile('^%s\\\\' % top)
    33     fixroot = re.compile('^%s\\\\' % top)
    34     for root, dirs, files in os.walk(top, topdown=True):
    34     for root, dirs, files in os.walk(top, topdown=True):
    35         for dirname in dirs:
    35         for dirname in dirs:
    36             if(string.lower(fixpath.sub('/',os.path.join(root,dirname))) in exclude_dirs):
    36             if(string.lower(fixpath.sub('/',os.path.join(root,dirname))) in exclude_dirs):
    37               dirs.remove(dirname)
    37               dirs.remove(dirname)
    38         for name in files:
    38         for name in files:
    39             filename = os.path.join(root, name)
    39             filename = os.path.join(root, name)
    40             fn = string.lower(fixpath.sub('/',fixroot.sub('',filename)))
    40             fn = string.lower(fixpath.sub('/',fixroot.sub('',filename)))
    41             print fn
    41             print fn.strip(directory)
    42 
    42 
    43 main()
    43 main()