import os, datetime
filename = '/Users/kwsy/kwsy/coolpython/demo.py'
# 文件大小
filesize = os.path.getsize(filename)
print(filesize) # 字节数
# 文件创建日期
create_time = os.path.getctime(filename) # 返回的是时间戳
print(datetime.datetime.fromtimestamp(create_time))
# 文件最近访问时间
access_time = os.path.getatime(filename)
print(access_time)
# 文件最近修改时间
modify_time = os.path.getmtime(filename)
print(modify_time)
计算时间差
def del_over_2days():
raw_dir = r"D:\download\flink"
file_list = os.listdir(raw_dir)
for file in file_list:
file_path = os.path.join(raw_dir, file)
print(file_path)
modify_time = os.path.getmtime(file_path)
print(modify_time)
print(datetime.fromtimestamp(modify_time))
days = (datetime.now() - datetime.fromtimestamp(modify_time) ).days
print(days)
print(len(file_list))