To update the filename according to its created time or modified time, a function is a good way.
def getMdate(file):
'''return: modified time of a file'''
import time
# os.stat return properties of a file
tmpTime = time.localtime(os.stat(file).st_mtime)
return time.strftime('%Y-%m-%d', tmpTime)
And with simple change of variables:
def getCdate(file):
'''return: created time of a file'''
import time
# os.stat return properties of a file
tmpTime = time.localtime(os.stat(file).st_ctime)
return time.strftime('%Y-%m-%d', tmpTime)
Both of which return date in yyyy-mm-dd format.