【问题标题】:Fastest way to check in python if a file exists and get its path in a very wide tree of subdirectories [duplicate]如果文件存在并在非常宽的子目录树中获取其路径,最快的方法是检查 python [重复]
【发布时间】:2014-08-09 18:22:45
【问题描述】:

所以我的问题是我有一个包含 1000 多个子目录的目录,我想要最有效的方法来检查某个文件是否在其中。有没有办法做到这一点,而无需遍历每个目录,直到我找到它?我更喜欢pythonic的方式来做这件事,但是只要它是有效的,任何可以通过 os.system 运行的东西都是可以接受的。谢谢!

【问题讨论】:

    标签: python directory find binary-search-tree directory-structure


    【解决方案1】:

    正如http://bugs.python.org/issue11406 中提到的,walk 比它应该的要慢,社区当然想出了一个替代方案。

    假设fastest 是指运行时间,您应该使用scandirhttps://github.com/benhoyt/scandir/#readme

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-12
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 2013-04-07
      • 2015-08-01
      • 1970-01-01
      • 2014-12-06
      相关资源
      最近更新 更多