import os
from datetime import datetime, timedelta
now = datetime(2008, 10, 14, 00, 00, 00)
def yours(days):
for fl in sorted(os.listdir('.')):
e = now - timedelta(days=days)
inputdatef = e.strftime("%Y%m%d%H%M")
if inputdatef in fl:
print fl
days = days - 1
def another(days):
files = sorted(os.listdir('.'))
for fl in sorted(os.listdir('.')):
for day in range(1, days+1):
e = now - timedelta(days=day)
inputdatef = e.strftime("%Y%m%d%H%M")
if inputdatef in fl:
print fl
print '# yours'
yours(2)
print '# another'
another(2)
---
# yours
# another
PUBLIC_TRADINGIS_200810120000.zip
PUBLIC_TRADINGIS_200810130000.zip
---
BTW: you may want to take a closer look at your use of strftime. In your code the timestamp you create will always use the hour and minute that the script is executed (from datetime.now()) which I presume is not what you intended.
|