common/tools/listdir.py
changeset 351 a4c764727769
child 964 e06b37cce80d
equal deleted inserted replaced
350:1e8f54745323 351:a4c764727769
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 # Initial Contributors:
       
     8 # Symbian Foundation Ltd - initial contribution.
       
     9 #
       
    10 # Contributors:
       
    11 # mattd <mattd@symbian.org>
       
    12 #
       
    13 # Description:
       
    14 # listdir.py - Lists a directory contents.
       
    15 # listdir.py <directory> (<exclude_directory>)
       
    16 
       
    17 import os
       
    18 import re
       
    19 import sys
       
    20 import string
       
    21 from os.path import join, isfile
       
    22 
       
    23 def main():
       
    24   directory = sys.argv[1]
       
    25   exclude_dirs = []
       
    26   if(len(sys.argv)>2):
       
    27     x_dirs = string.lower(sys.argv[2])
       
    28     exclude_dirs = re.split(',', x_dirs)
       
    29   scandir(directory, exclude_dirs)
       
    30 
       
    31 def scandir(top, exclude_dirs):
       
    32     fixpath = re.compile('\\\\')    
       
    33     fixroot = re.compile('^%s\\\\' % top)
       
    34     for root, dirs, files in os.walk(top, topdown=True):
       
    35         for dirname in dirs:
       
    36             if(string.lower(fixpath.sub('/',os.path.join(root,dirname))) in exclude_dirs):
       
    37               dirs.remove(dirname)
       
    38         for name in files:
       
    39             filename = os.path.join(root, name)
       
    40             fn = string.lower(fixpath.sub('/',fixroot.sub('',filename)))
       
    41             print fn
       
    42 
       
    43 main()