Latest web development tutorials

파이썬 os.utime () 메소드

파이썬 파일 (파일) 방법 파이썬 OS 파일 / 디렉토리 방법


개요

os.utime () 메서드는 경로 지정된 파일을 마지막으로 수정 및 액세스 시간을 설정하는 데 사용됩니다.

유닉스, 윈도우 효과적으로.

문법

다음과 같이utime와 () 메서드 구문은 다음과 같습니다

os.utime(path, times)

매개 변수

  • 경로 - 파일 경로

  • 시간은 - 시간 및 액세스 중에 변형되지 않는 경우, 파일은 현재 시간으로 설정된다.그렇지 않으면, 시간은 액세스 및 수정 시간으로 사용 된 디지털 2 튜플 (atime에, mtime에)입니다.

반환 값

이 메소드는 반환 값이 없습니다.

다음의 예는 utime와 () 메소드를 사용하는 방법을 보여줍니다 :

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

import os, sys

# 显示文件的 stat 信息
stinfo = os.stat('a2.py')
print stinfo

# 使用 os.stat 来接收文件的访问和修改时间
print "a2.py 的访问时间: %s" %stinfo.st_atime
print "a2.py 的修改时间: %s" %stinfo.st_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)
a2.py 的访问时间: 1330498070
a2.py 的修改时间: 1330498074
done!!

파이썬 파일 (파일) 방법 파이썬 OS 파일 / 디렉토리 방법