Skip to content

Instantly share code, notes, and snippets.

@achtan
Last active December 14, 2015 02:19
Show Gist options
  • Save achtan/5013296 to your computer and use it in GitHub Desktop.
Save achtan/5013296 to your computer and use it in GitHub Desktop.
rename files in folder by date created
import datetime
import os
dir = os.getcwd() + '/'
for filename in os.listdir(dir):
newName = datetime.datetime.fromtimestamp(os.path.getmtime(dir + filename)).strftime('%Y%m%d-%H%M%S') + os.path.splitext(filename)[1]
print('rename: ' + filename + ' -> ' + newName)
os.rename(dir + filename, dir + newName)
print('done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment