ファイル名からタイムスタンプを変更するPythonスクリプトの紹介
#coding:utf-8
import sys
import os
import re
import glob
import time
from datetime import datetime
print ("filename2timestamp")
print (os.getcwd())
pattern = r"^(\d{4})[^\d]*(\d{1,2})[^\d]*(\d{1,2})[^\d]*(\d{1,2})[^\d]*(\d{1,2})(?:[^\d]*(\d{1,2})){0,1}"
for x in glob.glob("*.*"):
sys.stdout.write(x + " -> ")
matchOB = re.match(pattern , x)
if matchOB:
atime = mtime = time.mktime((int(matchOB.group(1)),int(matchOB.group(2)),int(matchOB.group(3)),int(matchOB.group(4)),int(matchOB.group(5)),int(matchOB.group(6)), 0, 0, -1))
os.utime(x, (atime, mtime))
print (datetime.fromtimestamp(os.stat(x).st_mtime))
else:
print ("unmatch")