| | |
File Modification Time
Thread Solved
![]() |
The functions are contained in module os. Function os.path.getmtime() gives you the last modified time in seconds since the beginning of 1/1/1970 (epoch). You have to do some formatting with module time functions to make it readable for the ordinary mortal.
The size of the file is returned by os.path.getsize() in bytes, convert to kilobytes and format the result.
Similarly function os.path.getatime() gives the last access time.
The size of the file is returned by os.path.getsize() in bytes, convert to kilobytes and format the result.
python Syntax (Toggle Plain Text)
import os import time # pick a file you have in the working folder ... fname = "Texture.py" print "File was last modified (12 hour format):" print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname))) fsize = os.path.getsize(fname) print "size = %0.1f kb" % float(fsize/1000.0) """ possible result: File was last modified (12 hour format): 01/25/2003 11:38:30 AM size = 5.8 kb """
Last edited by vegaseat; Aug 12th, 2009 at 6:00 pm. Reason: tags
May 'the Google' be with you!
A kbyte is 1024 bytes. This would be more correct:
Python Syntax (Toggle Plain Text)
fsize = os.path.getsize(fname) print "size = %0.1f kb" % float(fsize/1024.0)
![]() |
Similar Threads
- how to set file access time (C)
- copy a file (Python)
- How to Get Last Accessed/Created/Modified File Date and Time (C)
Other Threads in the Python Forum
- Previous Thread: adding values of dictionaries
- Next Thread: Error trapping while reading windows XP registry entries
| Thread Tools | Search this Thread |
abrupt accessdenied ansi anti apache application approximation argv array assignment backend beginner binary bluetooth builtin calculator change character converter countpasswordentry curved customdialog dan08 dictionary dynamic edit exe file float format function graphics heads homework ideas inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook pointer prime programming progressbar py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session software sprite statictext statistics string strings syntax terminal text thread threading time tlapse tuple twoup ubuntu unicode unit urllib urllib2 variable wordgame write wxpython xlib






