how to "touch" a file

Jeff Epler jepler at
Tue Mar 23 16:42:37 CET 2004

I think that "touch -m" works like this function, by using stat to get
the atime, then setting an identical atime and new mtime with utime.

def set_mtime(fn, mtime=None):
    if mtime is None: mtime = time.time()
    atime = os.stat(fn).st_atime
    os.utime(fn, (atime, mtime))


More information about the Python-list mailing list