thanks for responding. Glob and os.walk will work but I would need to type up a separate command for each month of each year and that doesn't seem very efficient. Is there a way to make it go through and group txt files with similar filenames e.g something like: if fname.endswith('.txt')and fname[0:7]==fname[0:7] e.g. r20110101.txt and r20110102.txt should go together but r20110601 should not. thanks
On Tue, Apr 3, 2012 at 4:59 PM, Alan Gauld <alan.ga...@btinternet.com>wrote: > 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/ > > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor