I have files named in the format gtYYMMDD.txt like for example gt130422.txt, I'd like to extract the date from this file name in the format 2013/04/22.
I'd like to precise that my script, when I execute it, it asks only for the date:
filetoread = "/home/scripts/gt"
raw_input("Enter date, please. For example, 130415: ") + ".txt"
>>> from datetime import datetime >>> filetoread = "/home/scripts/gt/" >>> s = raw_input("Enter date please e.g: 130415: ") Enter date please e.g: 130415: 130422 >>> date = datetime.strptime(s, '%y%m%d') >>> print date.strftime("%Y/%m/%d") 2013/04/22 >>> path = filetoread + s + ".txt"