Re: Sorting directory contents

2007-02-21 Thread Wolfgang Draxinger
Tim Williams wrote: Are you running on windows? No. Of course I could use some installed tool, like ls, but I want a portable solution. HTH :) Not really. Windows is only a niche for desktop systems. In my case the python script is running on a heterogenous grid monitoring system accessing a

Re: Sorting directory contents

2007-02-21 Thread Peter Otten
Wolfgang Draxinger wrote: I got, hmm not really a problem, more a question of elegance: In a current project I have to read in some files in a given directory in chronological order, so that I can concatenate the contents in those files into a new one (it's XML and I have to concatenate

Re: Sorting directory contents

2007-02-21 Thread Jussi Salmela
Larry Bates kirjoitti: Wolfgang Draxinger wrote: Jussi Salmela wrote: I'm not claiming the following to be more elegant, but I would do it like this (not tested!): src_file_paths = dict() prefix = sourcedir + os.sep for fname in os.listdir(sourcedir): if match_fname_pattern(fname):

Sorting directory contents

2007-02-20 Thread Wolfgang Draxinger
H folks, I got, hmm not really a problem, more a question of elegance: In a current project I have to read in some files in a given directory in chronological order, so that I can concatenate the contents in those files into a new one (it's XML and I have to concatenate some subelements, about 4

Re: Sorting directory contents

2007-02-20 Thread Jussi Salmela
Wolfgang Draxinger kirjoitti: H folks, I got, hmm not really a problem, more a question of elegance: In a current project I have to read in some files in a given directory in chronological order, so that I can concatenate the contents in those files into a new one (it's XML and I have to

Re: Sorting directory contents

2007-02-20 Thread Wolfgang Draxinger
Jussi Salmela wrote: I'm not claiming the following to be more elegant, but I would do it like this (not tested!): src_file_paths = dict() prefix = sourcedir + os.sep for fname in os.listdir(sourcedir): if match_fname_pattern(fname): fpath = prefix + fname

Re: Sorting directory contents

2007-02-20 Thread Larry Bates
Wolfgang Draxinger wrote: Jussi Salmela wrote: I'm not claiming the following to be more elegant, but I would do it like this (not tested!): src_file_paths = dict() prefix = sourcedir + os.sep for fname in os.listdir(sourcedir): if match_fname_pattern(fname): fpath =

Re: Sorting directory contents

2007-02-20 Thread Paul Rubin
Wolfgang Draxinger [EMAIL PROTECTED] writes: src_file_paths = dict() for fname in os.listdir(sourcedir): fpath = sourcedir+os.sep+fname if not match_fname_pattern(fname): continue src_file_paths[os.stat(fpath).st_mtime] = fpath for ftime in

Re: Sorting directory contents

2007-02-20 Thread Jussi Salmela
Wolfgang Draxinger kirjoitti: Jussi Salmela wrote: I'm not claiming the following to be more elegant, but I would do it like this (not tested!): src_file_paths = dict() prefix = sourcedir + os.sep for fname in os.listdir(sourcedir): if match_fname_pattern(fname): fpath =

Re: Sorting directory contents

2007-02-20 Thread Rob Wolfe
Wolfgang Draxinger wrote: However this code works (tested) and behaves just like listdir, only that it sorts files chronologically, then alphabetically. def listdir_chrono(dirpath): import os files_dict = dict() for fname in os.listdir(dirpath):

Re: Sorting directory contents

2007-02-20 Thread Wolfgang Draxinger
Larry Bates wrote: 3) You didn't handle the possibility that there is s subdirectory in the current directory. You need to check to make sure it is a file you are processing as os.listdir() returns files AND directories. Well, the directory the files are in is not supposed to have

Re: Sorting directory contents

2007-02-20 Thread Tim Williams
On 20/02/07, Wolfgang Draxinger [EMAIL PROTECTED] wrote: H folks, I got, hmm not really a problem, more a question of elegance: In a current project I have to read in some files in a given directory in chronological order, so that I can concatenate the contents in those files into a new one