| | |
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 |
address alarm anydbm app beginner changecolor cipher clear conversion coordinates corners curves cx-freeze data definedlines development dictionary directory dynamic events excel feet file float format function generator getvalue halp handling homework images import input ip itunes java keycontrol line linux list lists loan loop maintain matching maze millimeter mouse number numbers output parsing path port prime programming py2exe pygame pymailer python queue random rational raw_input recursion recursive screensaverloopinactive script scrolledtext searchingfile slicenotation split ssh string strings tails text threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable variables ventrilo vigenere web webservice word wxpython xlwt






