1import fnmatch
2import os
3import sys
4
5dirs = [ ]
6types = [ ]
7excludes = [ ]
8files = [ ]
9
10# Default to accepting a list of directories first
11curArray = dirs
12
13# Iterate over the arguments and add them to the arrays
14for 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
32if len(dirs) == 0:
33    dirs.append(".")
34
35# If no types were specified, accept all types
36if len(types) == 0:
37    types.append("*")
38
39# Walk the directories listed and compare with type and exclude lists
40for 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
60files.sort()
61for file in files:
62    print file
63