• 使用python删除N天前的文件(2)


    import os
    import sys
    import time
     
    # Sets how many days old files are deleted
    DAYS_N = 7
    # To delete the path and the following subfiles
    PATH = r'C:\inetpub\logs\LogFiles'
     
    def deletefile(PATH):
        for eachfile in os.listdir(PATH):
            filename = os.path.join(PATH, eachfile)
            if os.path.isfile(filename):
                lastmodifytime = os.stat(filename).st_mtime
                # Sets how many days old files are deleted
                endfiletime = time.time() - 3600 * 24 * DAYS_N
                if endfiletime > lastmodifytime:
                    # To remove the following comment is to delete the.log suffix file
                    # Comment is delete path under all files do not match
                    if filename[-4:] == ".log":
                        os.remove(filename)
                        print "del %s success!!!" % filename
            # If it is a directory, the current function is called recursively
            elif os.path.isdir(filename): 
                deletefile(filename)
     
    if __name__ == '__main__':
        deletefile(PATH)
         
    time.sleep(1)
    print ('Deleting completed,success')
    
  • 相关阅读:
    5. JVM虚拟机栈
    4. 程序计数器
    3. JVM运行时数据区
    2. 类加载
    1. JVM体系结构
    SpringCloud 网关组件Gateway
    SpringCloud Hystrix断路器的基本使用
    SpringCloud Ribbon和Feign 的使用和源码分析
    反向代理的概念
    事务mysql
  • 原文地址:https://www.cnblogs.com/interdrp/p/15631622.html
Copyright © 2020-2023  润新知