有时候用到,记录一下

# -*- coding: UTF8 -*-

import os
import time

def TimeStampToTime(timestamp):

timeStruct = time.localtime(timestamp)
return time.strftime('%Y-%m-%d %H:%M:%S', timeStruct)

def get_FileCreateTime(filePath):

# '''获取文件的创建时间'''
# filePath = unicode(filePath,'utf8')
t = os.path.getctime(filePath)
return TimeStampToTime(t)

def get_FileModifyTime(filePath):

# '''获取文件的修改时间'''
# filePath = unicode(filePath, 'utf8')
t = os.path.getmtime(filePath)
return TimeStampToTime(t)

def get_FileAccessTime(filePath):

# '''获取文件的访问时间'''
# filePath = unicode(filePath, 'utf8')
t = os.path.getatime(filePath)
return TimeStampToTime(t)

def get_FileSize(filePath):

# '''获取文件的大小,结果保留两位小数,单位为MB'''
# filePath = unicode(filePath,'utf8')
fsize = os.path.getsize(filePath)
fsize = fsize / float(1024 * 1024)
return round(fsize, 2)

if name == '__main__':

path = r"D:\Desktop\实际图每隔30分钟\kevin_picture_alg_need_collect"
print(get_FileCreateTime(path))
print(get_FileModifyTime(path))
print(get_FileAccessTime(path))
print(get_FileSize(path))
Last modification:April 15th, 2022 at 08:39 pm