Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34980

Re: Iterating over files of a huge directory

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.033
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'python': 0.09; 'received :mail-vc0-f174.google.com': 0.09; 'subject:files': 0.09; 'dec': 0.15; '2:28': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'gilles': 0.16; 'googled': 0.16; 'iterator': 0.16; 'reasonably': 0.16; 'wrote:': 0.17; 'memory': 0.18; 'header :In-Reply-To:1': 0.25; 'creating': 0.26; 'am,': 0.27; 'in.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'giant': 0.29; 'received:209.85.220.174': 0.29; 'yields': 0.29; "i'm": 0.29; 'problem.': 0.32; 'url:python': 0.32; 'file': 0.32; 'structure': 0.32; 'says': 0.33; 'surely': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'kind': 0.61; 'customer': 0.61; 'potentially': 0.66; 'sounds': 0.71; 'subject:over': 0.84; 'zen': 0.84; 'hundred': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=2yImHUj9MmJpxOhnXuGGlw8KzeHS0bWlHJKfMJd2kHQ=; b=RfRRhkipcgzpSgnwZ9BUMCDY37OpdDJR5YmTXYo8SzVOfwwJ4XwbnLc+bPHYo3KLrV Igjzs8Es177W16S4oacCK+QuQFdFY0EiFvY9MBu0L+DmTGKGJfXM8yNMGBYGS0dfDcp4 iiKJHNNjo8WFqR2m4ypYp/6apzvgfFFmFR51hZeDSHC+9JWq+94T0OIy13+wHSQq5bHn awp7pakmVg36N/P0Dl6/nG4/4AmvaY3iVndQSH9da/DR9D2DyIvWDA1pSEfk3Ngnlhmv 8PHHeNQKvyiVZ6a1kv1zhbfXsjqgksgrlTx/BiBOzSAJ4b4Ad8fgyAjpVEVE+VIWdoJi NKsQ==
MIME-Version 1.0
In-Reply-To <c2b15410-12e0-4645-a77f-9944bfd674a8@googlegroups.com>
References <c2b15410-12e0-4645-a77f-9944bfd674a8@googlegroups.com>
Date Tue, 18 Dec 2012 02:41:42 +1100
Subject Re: Iterating over files of a huge directory
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.961.1355758912.29569.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355758912 news.xs4all.nl 6887 [2001:888:2000:d::a6]:56690
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34980

Show key headers only | View raw


On Tue, Dec 18, 2012 at 2:28 AM, Gilles Lenfant
<gilles.lenfant@gmail.com> wrote:
> Hi,
>
> I have googled but did not find an efficient solution to my problem. My customer provides a directory with a huuuuge list of files (flat, potentially 100000+) and I cannot reasonably use os.listdir(this_path) unless creating a big memory footprint.
>
> So I'm looking for an iterator that yields the file names of a directory and does not make a giant list of what's in.

Sounds like you want os.walk. But... a hundred thousand files? I know
the Zen of Python says that flat is better than nested, but surely
there's some kind of directory structure that would make this
marginally manageable?

http://docs.python.org/3.3/library/os.html#os.walk

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Iterating over files of a huge directory Gilles Lenfant <gilles.lenfant@gmail.com> - 2012-12-17 07:28 -0800
  Re: Iterating over files of a huge directory Chris Angelico <rosuav@gmail.com> - 2012-12-18 02:41 +1100
    Re: Iterating over files of a huge directory Paul Rudin <paul.nospam@rudin.co.uk> - 2012-12-17 17:27 +0000
      Re: Iterating over files of a huge directory MRAB <python@mrabarnett.plus.com> - 2012-12-17 18:29 +0000
      Re: Iterating over files of a huge directory Chris Angelico <rosuav@gmail.com> - 2012-12-18 08:10 +1100
  Re: Iterating over files of a huge directory Tim Golden <mail@timgolden.me.uk> - 2012-12-17 15:48 +0000
  Re: Iterating over files of a huge directory Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-17 15:52 +0000
    Re: Iterating over files of a huge directory Gilles Lenfant <gilles.lenfant@gmail.com> - 2012-12-17 08:06 -0800
    Re: Iterating over files of a huge directory Gilles Lenfant <gilles.lenfant@gmail.com> - 2012-12-17 08:06 -0800
  Re: Iterating over files of a huge directory marduk <marduk@python.net> - 2012-12-17 10:50 -0500
  Re: Re: Iterating over files of a huge directory Evan Driscoll <driscoll@cs.wisc.edu> - 2012-12-17 12:40 -0600
  Re: Re: Iterating over files of a huge directory Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-17 19:50 +0000
  Re: Iterating over files of a huge directory Evan Driscoll <driscoll@cs.wisc.edu> - 2012-12-17 14:09 -0600
  Re: Iterating over files of a huge directory Terry Reedy <tjreedy@udel.edu> - 2012-12-17 16:27 -0500

csiph-web