2

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?

viuser
  • 953
  • 6
  • 19

1 Answers1

3

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

mVChr
  • 49,587
  • 11
  • 107
  • 104