Senin, 09 Desember 2013

Get Modification Time of File in Python

'''
Created on Dec 9, 2013

@author: BalonCoding
'''
import os
  
fileName = 'c:\\fm\\fmb\\MTR00035.fmb'
#using os.stat.st_mtime
st=os.stat(fileName)    
mtime=st.st_mtime
print("mtime (using os.stat.st_mtime) = " + str(mtime))
#mtime (using os.stat.st_mtime) = 1141933677.28125

#using os.path.getmtime
print("mtime (using os.path.getmtime) = " + str(os.path.getmtime(fileName)))
#mtime (using os.path.getmtime) = 1141933677.28125


############################################################################################
import datetime

#using datetime.datetime
print("mtime (using datetime.datetime) = {}".format(datetime.datetime.fromtimestamp(mtime)))
#mtime (using datetime.datetime) = 2006-03-10 02:47:57.281250


############################################################################################
import stat, time
print("mtime (using time.ctime ) = {}".format(time.ctime(st[stat.ST_MTIME])))
#mtime (using time.ctime ) = Fri Mar 10 02:47:57 2006

Tidak ada komentar:

Posting Komentar