[Tutor] group txt files by month
Alan Gauld
alan.gauld at btinternet.com
Tue Apr 3 08:59:56 CEST 2012
On 03/04/12 04:59, questions anon wrote:
> I have a list of txt files that contain daily rainfall for many years.
> They are set out like:
> r20110101.txt
> r20110102.txt
> r20110103.txt
> and so on for each day for many years.
>
> MainFolder=r"E:/Rainfalldata/"
> outputFolder=r"E:/test/"
> for (path, dirs, files) in os.walk(MainFolder):
If the files are all in a single folder you might be better using
glob.glob() rather than os.walk. You can pass a filename pattern
like *.txt to glob(). This might make it easier to group the
files by year... 2010*.txt for example.
You can do it with walk too its just a bit more effort. But if the files
are in multiple folders walk() is probably better.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list