I want to change the modification and creation time of any file with python. This would be the command I use in Linux:
touch -a -m -t 201512180130.09 ./file.jpg
Then I check the following I can see the date is changed correctly:
$ls -l --time-style=full-iso
-rw-rw-r-- 1 me me 44570 2015-12-18 01:30:09.000000000 -0500 file.jpg
$exiftool ./file.jpg | grep -i date
File Modification Date/Time : 2015:12:18 01:30:09-05:00
File Access Date/Time : 2015:12:18 01:30:09-05:00
File Inode Change Date/Time : 2022:12:13 19:39:43-05:00
I tried using the Pathlib('./file.jpg').touch()
and os.utime('./file.jpg', None)
. neither worked.
How can I do this in Python without having to use os or subprocess commands?