Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 listdir!)
os.walk

I cant find any good lib. help! Maybe c++ lib?

like image 674
fun_vit Avatar asked Feb 25 '11 11:02

fun_vit


People also ask

How do I list all files of a directory python?

To get a list of all the files and folders in a particular directory in the filesystem, use os. listdir() in legacy versions of Python or os. scandir() in Python 3.

How can I list all files of a directory in python and add them to a list?

listdir() method gets the list of all files and directories in a specified directory. By default, it is the current directory.


1 Answers

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

like image 159
miguelfg Avatar answered Oct 22 '22 18:10

miguelfg