listdir() - any way to limit # of file entries?
Paul Rubin
http
Wed Feb 22 17:15:04 EST 2006
Peter A. Schott <paschott at no.yahoo.spamm.com> writes:
> Is there any way to build a list of the first 1000 files or so in a folder?
The obvious way is
first_1000 = os.listdir()[:1000]
That does build a potentially bigger list in memory before chopping
off the 1000 elements, but unless you're running out of memory to hold
the list (which these days probably means millions of files in the
directory), don't worry about it.
More information about the Python-list
mailing list