How to change the file creation timestamp?

Alec Taylor alec.taylor6 at gmail.com
Fri Nov 25 08:51:34 EST 2011


import os
import time
from stat import *

#returns a list of all the files on the current directory
files = os.listdir('.')

for f in files:
  #my folder has some jpegs and raw images
  if f.lower().endswith('jpg') or f.lower().endswith('crw'):
    st = os.stat(f)
    atime = st[ST_ATIME] #access time
    mtime = st[ST_MTIME] #modification time

    new_mtime = mtime + (4*3600) #new modification time

    #modify the file timestamp
    os.utime(f,(atime,new_mtime))

On Fri, Nov 25, 2011 at 11:47 PM, 刘振海 <1989lzhh at gmail.com> wrote:
> Hi,
> I want to change the file creation timestamp using python, but I can not
> find a solution to do it.
> I know the way to change the file creation timestamp in C under Windows, but
> I want to change it using python.
> I really need help!
>
> Regards,
> Liu Zhenhai
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list