我需要保留从4月31日开始到5月1日第二天结束的备份文件。每个文件夹的备份时间不同,但备份文件是相同的
这可能是解决问题的一种方法:os.path.getctime
获得文件的创建日期,os.path.getmtime
获得文件的最后修改日期
import os
if os.path.getctime("test.txt") > os.path.getctime("test2.txt"):
print("test.txt is more recent")
os.remove("test2.txt")
else:
print("test2.txt is more recent")
os.remove("test.txt")