我试了很多次,那位高手可以帮助解决下,不要只一句话。我需要详细方案。我试验了各种类型转换,如果真的能帮手解决 可以将费用全部给你 下面为代码. 我目前用比较时间段(01:00:00-22:00) 结果还是将不符合条件的00:45文件也复制,说明时间判断未起作用。
time_interval_one = Interval("01:00:00", "22:30:00")
# today = datetime.date.now()
# yesterday = today - datetime.timedelta(days=1)
d_time = datetime.datetime.strptime(str(datetime.datetime.now().date())+'15:30','%Y-%m-%d%H:%M')
print("d_time",d_time)
# now_20=datetime.datetime.now() - timedelta(hours=17)
# print("now_20",now_20)
if not os.path.exists(toPath):
os.mkdir(Guest)
if os.path.exists(dirPath):
for file in os.listdir(dirPath):
if os.path.isfile(dirPath+'/'+file):
if key in file:
create_time=time.localtime(os.path.getmtime(dirPath))
print("create_time",create_time)
filedate=time.strftime("%Y-%m-%d %H:%M:%S",create_time)
print("filedate",filedate)
hms=time.strftime("%H:%M:%S",create_time)
print("hms",hms)
# a=str(filedate)
# b=str(d_time)
# print("a",a)
# print("b",b)# if str(filedate)>(now_20):
if filedate in time_interval_one:
# if "15:30:00">filedate>"18:30:00":
copy2(dirPath+'/'+file, toPath+'/'+file)
print("copy2 succiss")
print("d_time",d_time)
else:
print("no match data")