best way to get files list of big directory on python?

后端 未结 9 1306
闹比i
闹比i 2021-02-07 22:36

I have insane big directory. I need to get filelist via python.

In code i need to get iterator, not list. So this not work:

os.listdir
glob.glob  (uses l         


        
相关标签:
9条回答
  • 2021-02-07 23:31

    You should use generator. This problem is discussed here: http://bugs.python.org/issue11406

    0 讨论(0)
  • 2021-02-07 23:33

    for python 2.X

    import scandir
    scandir.walk()
    

    for python 3.5+

    os.scandir()
    

    https://www.python.org/dev/peps/pep-0471/

    https://pypi.python.org/pypi/scandir

    0 讨论(0)
  • 2021-02-07 23:35

    I found this library useful: https://github.com/benhoyt/scandir.

    0 讨论(0)
提交回复
热议问题