时间间隔计算
now
= datetime
.datetime
.now().strftime("%Y-%m-%d %H:%M:%S") # 获取当前时间
now
= datetime
.datetime
.strptime(now
, '%Y-%m-%d %H:%M:%S')
terminal_time
= name
.update_time
.strftime("%Y-%m-%d %H:%M:%S")
terminal_time
= datetime
.datetime
.strptime(terminal_time
, '%Y-%m-%d %H:%M:%S')
time_stamp
.append((now
- terminal_time
).seconds
) # 计算终端更新的时间间隔
定期删除文件
def
fix_time_delete_folds():
"""
定期删除创建超过
5天的文件夹
"""
filePath
= r
"D:\DAC\static\solution\process"
delta
= datetime
.timedelta(days
=5) # 设定
5天前的文件为过期
now
= datetime
.datetime
.now() # 获取当前时间
os
.chdir(filePath
)
ds
= list(os
.listdir()) # 获得该目录下所有文件或文件夹列表
for d
in ds
: # 遍历该列表
if os
.path
.isdir(d
): # 如果列表项是文件夹
ctime
= datetime
.datetime
.fromtimestamp(os
.path
.getctime(d
)) # 获取文件创建时间
if ctime
< (now
- delta
): # 若创建于delta天前
shutil
.rmtree(d
)
转载请注明原文地址: https://lol.8miu.com/read-37190.html