Skip to content

Instantly share code, notes, and snippets.

@YUChoe
Created March 8, 2019 07:14
Show Gist options
  • Save YUChoe/c319d0111944f76a9b940ae36e7ae842 to your computer and use it in GitHub Desktop.
Save YUChoe/c319d0111944f76a9b940ae36e7ae842 to your computer and use it in GitHub Desktop.
import os
import time
start_timestamp = 1550587841
for serial in os.listdir('.'):
for fn in os.listdir(serial):
ctime = os.stat(os.path.join(serial, fn)).st_ctime
if ctime > start_timestamp:
date_in_filename = fn.split('_')[0]
date_in_file_ctime = time.strftime('%Y-%m-%d', time.localtime(ctime))
if date_in_filename != date_in_file_ctime:
profer_name = fn.replace(date_in_filename, date_in_file_ctime)
# fix error
src = os.path.join(serial, fn)
dst = os.path.join(serial, profer_name)
os.rename(src, dst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment