-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_utime.py
More file actions
42 lines (30 loc) · 1020 Bytes
/
os_utime.py
File metadata and controls
42 lines (30 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# encoding: utf-8
# @author: hoojo
# @email: hoojo_@126.com
# @github: https://github.com/hooj0
# @create date: 2018-04-01 17:14:10
# @copyright by hoojo@2018
# @changelog Added python3 `os dir -> utime` example
import os
'''
概述
os.utime() 方法用于设置指定路径文件最后的修改和访问时间。
在Unix,Windows中有效。
语法
utime()方法语法格式如下:
os.utime(path, times)
参数
path -- 文件路径
times -- 如果时间是 None, 则文件的访问和修改设为当前时间 。 否则, 时间是一个 2-tuple数字, (atime, mtime) 用来分别作为访问和修改的时间。
返回值
该方法没有返回值
'''
info = os.stat('/tmp/foo.txt')
print('info: %s' % info)
print('st_ctime: %s' % info.st_ctime)
print('st_mtime: %s' % info.st_mtime)
os.utime('/tmp/foo.txt', (1522073000, 1522073000))
info = os.stat('/tmp/foo.txt')
print('st_ctime: %s' % info.st_ctime)
print('st_mtime: %s' % info.st_mtime)