0

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!

martin
  • 1,145
  • 1
  • 7
  • 24
  • 1
    This [link](https://stackoverflow.com/questions/32455262/os-walk-very-slow-any-way-to-optimise) is worth a read. Turns out, if your python version is below 3.5, `os.walk()` might turn out to be slower for you. – tidakdiinginkan Apr 18 '20 at 03:16
  • 1
    Check out this [package](https://github.com/juancarlospaco/faster-than-walk#faster-than-walk) – tidakdiinginkan Apr 18 '20 at 03:19
  • Thank U! Any faster way is blessing for me :) – martin Apr 19 '20 at 14:10

0 Answers0