1

So my problem is I have a directory with over 1000 subdirectories and I want the most efficient way to check if a certain file is in them. Is there a way to do this without stepping through each directory until I find it? I would prefer a pythonic way of doing this but anything that can be run through os.system would be acceptable as long as it is efficient. Thank you!

Wes Field
  • 3,291
  • 6
  • 23
  • 26

1 Answers1

1

As mentioned in http://bugs.python.org/issue11406 walk is slower than it should be, community came up with an alternative of course.

Assuming that by fastest you mean run time, you should use scandir: https://github.com/benhoyt/scandir/#readme

Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120