Easy Tutorial
❮ Python Att List Insert Python Func Oct ❯

Python3 os.utime() Method

Python3 OS File/Directory Methods


Overview

The os.utime() method is used to set the last modification and access times of the specified file path.

This method is effective in Unix and Windows systems.

Syntax

The syntax for the utime() method is as follows:

os.utime(path, times)

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the utime() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

# Display the file's stat information
stinfo = os.stat('a2.py')
print (stinfo)

# Use os.stat to get the file's access and modification times
print ("a2.py's access time: %s" % stinfo.st_atime)
print ("a2.py's modification time: %s" % stinfo.st_mtime)

# Modify the access and modification times
os.utime("a2.py", (1330712280, 1330712292))
print ("done!!")

Executing the above program outputs the following:

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=1330498074, st_ctime=1330498065)
a2.py's access time: 1330498070
a2.py's modification time: 1330498074
done!!

Python3 OS File/Directory Methods

❮ Python Att List Insert Python Func Oct ❯