#-*- encoding=utf8 -*- import time import datetime import os '''把時間戳轉化為時間: 1479264792 to 2016-11-16 10:53:12''' def TimeStampToTime(timestamp): timeStruct = time.localtime(timestamp) return time.strftime('%Y-%m-%d %H:%M:%S',timeStruct) '''獲取文件的大小,結果保留兩位小數,單位為MB''' def get_FileSize(filePath): fsize = os.path.getsize(filePath) fsize = fsize/float(1024*1024) return round(fsize,5) '''獲取文件的訪問時間''' def get_FileAccessTime(filePath): t = os.path.getatime(filePath) return TimeStampToTime(t) '''獲取文件的創建時間''' def get_FileCreateTime(filePath): t = os.path.getctime(filePath) return TimeStampToTime(t) '''獲取文件的修改時間''' def get_FileModifyTime(filePath): t = os.path.getmtime(filePath) return TimeStampToTime(t) dirlist=["aaa"] print("獲取文件的修改時間") for i in dirlist: print(get_FileModifyTime(i)) print("獲取文件的創建時間") for i in dirlist: print(get_FileCreateTime(i)) print("獲取文件的訪問時間") for i in dirlist: print(get_FileAccessTime(i)) print("獲取文件的大小") for i in dirlist: print(get_FileSize(i))