Gary Herron <[EMAIL PROTECTED]> writes: > Gary Wessle wrote: > > >Hi > > > >is there a module to do things like concatenate all files in a given > >directory into a big file, where all the files have the same data > >formate? > >name address phone_no. > > > >or do I have to open each, read from old/write-or-append to new ... > > > >thanks > > > > > There's hardly enough code here to make a module out of this: > > combined = open('...', 'wb') > for name in os.listdir(path):
I need to traverse those files in the order they were created chronologically. listdir() does not do it, is there a way besides build a list then list.sort(), then for element in list_of_files open element? thanks > infile = open(os.path.join(path,name), 'rb') > for line in infile: > combined.write(line) > > It could be more efficient by reading larger chunks than single lines, > and could be more accurate by closing both input and output files when > done, but you get the point I hope. > > On the other hand, if you've got the right OS, you might try something like: > os.system("cat * > combined") > > Gary Herron -- http://mail.python.org/mailman/listinfo/python-list