How to you change the timestamp on a file to the current time? essentially just "touching" the file so the time is changed to the current time
Change timestamp on file to current time?
Page 1 of 13 Replies - 165 Views - Last Post: 18 January 2013 - 05:58 PM
Replies To: Change timestamp on file to current time?
#2
Re: Change timestamp on file to current time?
Posted 18 January 2013 - 05:47 PM
Take a look at the os.utime function:
Set the access and modified times of the file specified by path. If times is None, then the file’s access and modified times are set to the current time. (The effect is similar to running the Unix program touch on the path.)
Quote
os.utime(path, times)
Set the access and modified times of the file specified by path. If times is None, then the file’s access and modified times are set to the current time. (The effect is similar to running the Unix program touch on the path.)
This post has been edited by sepp2k: 18 January 2013 - 05:48 PM
#3
Re: Change timestamp on file to current time?
Posted 18 January 2013 - 05:48 PM
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))
#4
Re: Change timestamp on file to current time?
Posted 18 January 2013 - 05:58 PM
Thank you all for the help, got it!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|