zoukankan      html  css  js  c++  java
  • python 查看某个文件下最新更新的日期文件

     # 查看某个文件下最新更新的日期文件

    1
    import os 2 import datetime 3 import time 4 5 6 now_date = datetime.datetime.now().strftime('%Y%m%d%H%M') 7 # 获取文件夹日期 8 files_date = datetime.datetime.now().strftime('%Y-%m-%d') 9 # print(files_date,type(files_date)) 10 11 def files_report(report): 12 try: 13 start_time = time.time() 14 new_report = os.path.join(report,files_date) 15 # 列出目录的下所有文件和文件夹保存到lists 16 lists = os.listdir(new_report) 17 # 按照时间进行排序 18 lists.sort(key=lambda fn: os.path.getmtime(new_report + "\" + fn)) 19 # 获取最新的文件保存到file_new中 20 file_new = os.path.join(new_report, lists[-1]) 21 mod_date = time.strftime('%Y%m%d%H%M', time.localtime(os.path.getatime(file_new))) 22 # mod_date1 = time.strftime('%Y%m%d %H:%M', time.localtime(os.path.getatime(file_new))) 23 print(file_new,'当前文件夹时间是%s'%mod_date) 24 end_time =time.time() 25 # print(mod_date,type(mod_date)) 26 old_time = end_time - start_time 27 if mod_date == now_date: 28 print('查询耗时:',old_time) 29 return '正常' 30 else: 31 print('查询耗时:',old_time) 32 return '有问题,请检查!' 33 except Exception as e: 34 return '单日文件夹不存在,请检查!' 35 36 37 if __name__ == '__main__': 38 report = r"C:Users" # 目录地址 39 res = files_report(report) 40 print(res)
  • 相关阅读:
    cf-779E (拆位)
    石子游戏 (SG函数)
    [POI2017] Flappy Bird (思维题)
    Alice and Bob (SG函数)
    Red is good (DP)
    CodeVS-1669 (背包问题)
    GalaxyOJ-468 (LCA)
    BZOJ-1191 (二分图匹配)
    Reinforcement Learning 笔记(4)
    Reinforcement Learning 笔记(3)
  • 原文地址:https://www.cnblogs.com/Tang-Yuan/p/13265944.html
Copyright © 2011-2022 走看看