1 import fnmatch 2 import os 3 import sys 4 5 dirs = [ ] 6 types = [ ] 7 excludes = [ ] 8 files = [ ] 9 10 # Default to accepting a list of directories first 11 curArray = dirs 12 13 # Iterate over the arguments and add them to the arrays 14 for i in range(1, len(sys.argv)): 15 arg = sys.argv[i] 16 17 if arg == "-dirs": 18 curArray = dirs 19 continue 20 21 if arg == "-types": 22 curArray = types 23 continue 24 25 if arg == "-excludes": 26 curArray = excludes 27 continue 28 29 curArray.append(arg) 30 31 # If no directories were specified, use the current directory 32 if len(dirs) == 0: 33 dirs.append(".") 34 35 # If no types were specified, accept all types 36 if len(types) == 0: 37 types.append("*") 38 39 # Walk the directories listed and compare with type and exclude lists 40 for rootdir in dirs: 41 for root, dirnames, filenames in os.walk(rootdir): 42 for file in filenames: 43 # Skip files that are "hidden" 44 if file.startswith("."): 45 continue; 46 47 fullPath = os.path.join(root, file).replace("\\", "/") 48 for type in types: 49 if fnmatch.fnmatchcase(fullPath, type): 50 excluded = False 51 for exclude in excludes: 52 if fnmatch.fnmatchcase(fullPath, exclude): 53 excluded = True 54 break 55 56 if not excluded: 57 files.append(fullPath) 58 break 59 60 files.sort() 61 for file in files: 62 print file 63