Created
December 15, 2016 13:45
-
-
Save jpz/9a672f1e13ae6f919bb024ce87a49773 to your computer and use it in GitHub Desktop.
Touches the creation times (st_birthtime) back to the modified time for files on MacOS, where the creation time is greater than the modified datetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# this small script touches the creation times (st_birthtime) back to the modified time | |
# for files on MacOS, where the creation time is greater than the modified datetime. | |
# | |
# fixes a small problem I had with some very old photo files... | |
from subprocess import check_output, PIPE | |
import sys, dateparser | |
def get_creation_date(filename): | |
date = check_output(['GetFileInfo', '-d', filename], stdin=PIPE).decode("utf-8") | |
return dateparser.parse(date), date | |
def get_modification_date(filename): | |
date = check_output(['GetFileInfo', '-m', filename], stdin=PIPE).decode("utf-8") | |
return dateparser.parse(date), date | |
def set_creation_date(filename, date): | |
return dateparser.parse(check_output(['SetFile', '-d', date, filename], stdin=PIPE).decode("utf-8")) | |
for file in sys.argv[1:]: | |
crdate, crdatestr = get_creation_date(file) | |
moddate, moddatestr = get_modification_date(file) | |
print("checking " + file + ": ", end="") | |
if crdate > moddate: | |
print(crdate, moddate) | |
set_creation_date(file, moddatestr) | |
else: | |
print("OK") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment