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

后端 未结 9 1296
闹比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:30

    I found this library really fast.
    https://pypi.org/project/scandir/
    I used below code from this library, it worked like a charm.

    def subdirs(path):
    """Yield directory names not starting with '.' under given path."""
    for entry in os.scandir(path):
        if not entry.name.startswith('.') and entry.is_dir():
            yield entry.name
    

提交回复
热议问题