Python 獲取檔案的建立時間,修改時間和訪問時間
阿新 • • 發佈:2018-12-31
# 用到的知識
# os.path.getatime(file) 輸出檔案訪問時間
# os.path.getctime(file) 輸出檔案的建立時間
# os.path.getmtime(file) 輸出檔案最近修改時間
#-*- encoding=utf8 -*-
import time
import os
def fileTime(file):
return [
time.ctime(os.path.getatime(file)),
time.ctime(os.path.getctime(file)),
time.ctime(os.path.getmtime(file))]
times = fileTime("d")
#times = fileTime("ccc")
print(times)
檢視資料夾:
[email protected]:~/Desktop$ ls d/ fff hhh iii nnn ppp
touch 資料夾d裡面已經存在的檔案後,資料夾d的訪問時間,建立時間和最後修改時間不會變化
用 touch 在資料夾d中建立新檔案,資料夾d的建立時間和最後修改時間都會改變,且兩個時間相同
用vi 在資料夾d中建立新檔案,資料夾d的建立時間和最後修改時間都會改變,且兩個時間相同
編輯資料夾d裡面的檔案後,資料夾d的建立時間和最後修改時間都會變化,且兩個時間相同
ls d/,會導致d資料夾的訪問時間改變
檢視檔案:
[email protected]:~/Desktop$ ls ccc d
修改ccc檔案的內容,訪問時間,建立時間和最後修改時間都會改變,且時間相同
touch 已經存在的ccc檔案,ccc檔案的訪問時間,建立時間和最後修改時間都會改變,且時間相同