You are here : python_2ososutime

os.utime() - os

             

The method utime() sets the access and modified times of the file specified by path.


  • path -- This is the path of the file.

  • times -- This is the file access and modified time. If times is none, then the file access and modified times are set to the current time. The parameter times consists of row in the form of (atime, mtime) i.e (accesstime, modifiedtime).


Syntax


os.utime(path, times)


Example


# !/usr/bin/python

import os, sys

# Showing stat information of file
stinfo = os.stat('a2.py')
print stinfo

# Using os.stat to recieve atime and mtime of file
print "access time of a2.py: %s" %stinfo.st_atime
print "modified time of a2.py: %s" %stinfo.st_mtime

# Modifying atime and mtime
os.utime("a2.py",(1330712280, 1330712292))
print "done!!"


Output / Return Value

When we run above program, it produces following result:


posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st _nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498070, st_mtime=13 30498074, st_ctime=1330498065) access time of a2.py: 1330498070 modified time of a2.py: 1330498074 done!!


Limitations


Alternatives / See Also


Reference