I am iterating of folders and read files line by line in order to find some substring.
The problem is that I want to ignore some folders during search (like bin or build).
I tried to add check - but it still include it in the search
def step(ext, dirname, names): for name in names: if name.lower().endswith(".xml") or name.lower().endswith(".properties") or name.lower().endswith(".java"): path = os.path.join(dirname, name) if not "\bin\"" in path and not "\build" in path: with open(path, "r") as lines: print "File: {}".format(path) i = 0 for line in lines: m = re.search(r"\{[^:]*:[^\}]*\}", line) with open("search-result.txt", "a") as output: if m is not None: output.write("Path: {0}; \n Line number: {1}; \n String: {2}\n".format(path, i, m.group())) i+=1