I have a network disk with data. Many of dirs, many files. On disk I have some dirs with logs named LOGS_XXX, in those folders are various files and folders, including the folders I'm interested named YYYYFinal, where YYYY is year of created. So I just want to create list of path to that dirs but only if YYYY > 2017
. In one LOGS could be more than one YYYYFinal. Could be nothing interesting too.
So I put here a part code searching dirs by conditions and creating list:
path = path_to_network_drive
def findAllOutDirs(path):
finalPathList = []
for root, subdirs, files in os.walk(path):
for d in subdirs:
if d == "FINAL" or d == "Final":
outPath = root+r"\{}".format(d)
if ("LOGS" in outPath) and ("2018" in outPath or "2019" in outPath or "2020" in outPath):
finalPathList.append(outPath)
return finalPathList
And this code work good. I mean I got a final list but it take long time. So, maybe someone from here see some mistakes, bad using code or just know better option to do it by python?
Thanks!