最近使用Python写的一个监控脚本,获取文件的创建时间,由于使用了getctime导致出现问题。
由于我监控了log目录,而log目录会有进程对其进行chmod操作。导致获取的是最近修改时间。
正确的方法应该是使用getmtime,获取文件的创建时间。

import os
import time
file='/Volumes/Leopard/Users/Caroline/Desktop/1.mp4'
os.path.getatime(file)   #输出最近访问时间1318921018.0
os.path.getctime(file)   #输出文件创建时间
os.path.getmtime(file)   #输出最近修改时间
time.gmtime(os.path.getmtime(file))   #以struct_time形式输出最近修改时间
os.path.getsize(file)    #输出文件大小(字节为单位)
os.path.abspath(file)    #输出绝对路径'/Volumes/Leopard/Users/Caroline/Desktop/1.mp4'
os.path.normpath(file)   #输出'/Volumes/Leopard/Users/Caroline/Desktop/1.mp4'