pythonfindplatform-independence

OS independent method to find a file fast with Python


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?


Solution

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