OS independent method to find a file fast with Python

88 Views Asked by At

With Python, how do I search for a file in a directory (including subdirectories) fast?

The standard answers here utilize os.walk(), which is slow compared to just calling find /path -iname "*string*", if working under Linux.

Is there a clean platform-independent way to achieve a better speed?

1

There are 1 best solutions below

0
mVChr On BEST ANSWER

os.scandir (GitHub) is faster than os.walk and is now in the Python 3.5+ standard library.