Python-os-utime
提供:Dev Guides
Python os.utime()メソッド
説明
Pythonメソッド* utime()*は、pathで指定されたファイルのアクセス時刻と変更時刻を設定します。
構文
以下は* utime()*メソッドの構文です-
os.utime(path, times)
パラメーター
- path -これはファイルのパスです。
- times -これはファイルアクセスと変更時間です。 時間がゼロの場合、ファイルアクセス時間と変更時間は現在の時間に設定されます。 パラメーターtimeは、(atime、mtime)の形式の行で構成されます(つまり、accesstime、modifiedtime)。
戻り値
このメソッドは値を返しません。
例
次の例は、utime()メソッドの使用法を示しています。
# !/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!!"
上記のプログラムを実行すると、次の結果が生成されます-
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!!