 <p>From the <code>glob</code> module's <a href="http://docs.python.org/2/library/glob.html" rel="nofollow">documentation</a>:</p> <blockquote> <p>The <code>glob</code> module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell. No tilde expansion is done, but <code>*</code>, <code>?</code>, and character ranges expressed with <code>[]</code> will be correctly matched. <strong>This is done by using the <code>os.listdir()</code></strong> and <code>fnmatch.fnmatch()</code> functions in concert, and not by actually invoking a subshell.</p> </blockquote> <p>And if we look the documentation for <code>os.listdir</code>:</p> <blockquote> <p>os.listdir(path)</p> <p>Return a list containing the names of the entries in the directory given by path. <strong>The list is in arbitrary order</strong>. It does not include the special entries '.' and '..' even if they are present in the directory.</p> </blockquote> <p>So <code>glob.glob</code> does not return the files in alphabetical order. It is not stated anywhere in the documentation. Relying on this behaviour is a bug. If you want an ordered sequence you <em>must</em> sort the result. You can then easily imagine that there is no way to make <code>iglob</code> return a sorted result since it does not even have all results available.</p> <p>If memory is really a problem then you have two choices:</p> <ol> <li>Drop the "aplhabetical order" requirement and just use <code>iglob</code>.</li> <li>Sort the data using some kind of "bucket sorting", keeping most of the data on disk and loading it into RAM in chunks (such techniques are explained in The Art of Computer Programming, Book 3). This approach will make your program slower and probably much harder to write. But if you really can not hold all the filenames in RAM then you'll have to save them on disk eventually.</li> </ol>