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))
|