当检测到文件被更新时候,就打印出这个时间,当传入的所有文件都被更新后则退出脚本。但是现在每次执行完第一次都会出现大量打印时间。新手求解怎么改。。
4条回答 默认 最新
- qq_25594587 2021-05-17 15:26关注
def timer(pathList): ticks = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) print("currentTime" + ticks) b = True succes_list = [] while b: try: for element in pathList: if not os.path.exists(element): os.system(r"touch {}".format(element)) # 调用系统命令行来创建文件 mtime = os.path.getmtime(element) strTime = datetime.datetime.fromtimestamp(mtime) last_modified_date = strTime.strftime("%Y-%m-%d %H:%M:%S") dt1 = datetime.datetime.strptime(ticks, "%Y-%m-%d %H:%M:%S") dt2 = datetime.datetime.strptime(last_modified_date, "%Y-%m-%d %H:%M:%S") if dt1 < dt2: if element not in succes_list: succes_list.append(element) print(element + "flash", last_modified_date) if len(succes_list) == len(pathList): b = False except Exception as e: print(e) mtime = 0 sys.exit()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥35 平滑拟合曲线该如何生成
- ¥100 c语言,请帮蒟蒻写一个题的范例作参考
- ¥15 名为“Product”的列已属于此 DataTable
- ¥15 安卓adb backup备份应用数据失败
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 自己瞎改改,结果现在又运行不了了
- ¥15 链式存储应该如何解决
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站