Combining several text files
clp2 at rebertia.com
Mon Feb 2 19:17:43 CET 2009
On Mon, Feb 2, 2009 at 9:48 AM, Eric <eric.shain at gmail.com> wrote:
> This is my first post, so please advise if I'm not using proper
> etiquette. I've actually searched around a bit and while I think I can
> do this, I can't think of a clean elegant way. I'm pretty new to
> Python, but from what I've learned so far is that there is almost
> always an easier way.
> I have to parse several log files. I've already written a working
> parser. The log files are simple text files that when they get to a
> certain size are renamed to append a number. So, you might end up
> The higher the number, the older the file. I want to search for all
> the files in a directory with "filename.log" as part of their name.
> Then I can do one of two things. First I could combine them so that
> the resulting file ends up with the oldest on top and newest on the
> bottom. Otherwise, I could just iterate over the multiple files within
> my parser.
> I don't need working code (that makes things too easy), just clear
> suggestions to a Python newcomer to speed me on my way.
For listing the filenames, you'll want to use os.listdir:
or possibly the `glob` module depending on your needs:
Follow the path of the Iguana...
More information about the Python-list