Listing files in a directory with Python when the directory is huge
问题 I'm trying to deal with many files in Python. I first need to get a list of all the files in a single directory. At the moment, I'm using: os.listdir(dir) However. This isn't feasible since the directory I'm searching has upward of 81,000 files in it, and totals almost 5 Gigabytes. What's the best way of stepping through each file one-by-one? Without Windows deciding that the Python process is not responding and killing it? Because that tends to happen. It's being run on a 32-bit Windows XP