Op Tuesday 19 May 2015 23:28 CEST schreef Jon Ribbens: > On 2015-05-19, Cecil Westerhof <ce...@decebal.nl> wrote: >> It looks like that this does what I want (the dot is needed so that >> it also works with 2.7): files = sorted(os.listdir('.')) p = >> re.compile('actions-2015-05-[0-9][0-9].sql$') current_month = [ >> file for file in files if p.match(file) ] > > You could instead do (in Python 2 or 3): > > files = glob.glob("actions-2015-05-[0-9][0-9].sql") > files.sort()
Something to remember. But in this case I also need the previous month. So I have: files = sorted(os.listdir('.')) p = re.compile('actions-2015-05-[0-9][0-9].sql$') current_month = [ file for file in files if p.match(file) ] p = re.compile('actions-2015-04-[0-9][0-9].sql$') previous_month = [ file for file in files if p.match(file) ] Of-course I will not hard-code the months in the real code. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list