sorting directory
Sean 'Shaleh' Perry
shalehperry at attbi.com
Sun May 25 19:33:30 EDT 2003
On Sunday 25 May 2003 16:18, psybar phreak wrote:
> i am currently using glob (thanks to the wisdom of yee here) to filter
> a directory for files that end in certain extensions, as i get a
> match, i print out the contents. what i want to do now, however, is
> to sort these according to the file name, eg file1, comes before file
> 2.
>
> can i sort the directory contents, before i start filtering? or am i
> going to have to filter, put results in a list, then sort, then loop
> through list and print results? (i hope its the first one!)
>
> thanks!!
the answer is yes, but you may not want to (-:
Say you have several hundred files in the directory but only want 10, 20 or 30
of them. It *MAY* cause your script to be too slow for you. Something to
consider and test anyways.
More information about the Python-list
mailing list