Skip to content

Instantly share code, notes, and snippets.



Created Nov 6, 2015
What would you like to do?
Change Modification Date via Python

This is Python code for updating the file modification date of a file on MacOSX or Linux. In this example, I had copied .dv files from my camcorder, which encoded the date in the filename, but had as the modification date, the time I transferred the file from the camcorder.

import os
import time
fpath = '/path/to/dv/files'
for root, dirs, files in os.walk(fpath):
    for name in files:
        if name[-3:]=='.dv':
                t = time.mktime(time.strptime(name, 'clip-%Y-%m-%d %H;%M;%S.dv'))
                os.utime(os.path.join(root,name), (t,t))
            except ValueError as err:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.