`
ppju
  • 浏览: 78262 次
  • 性别: Icon_minigender_1
  • 来自: 西安
文章分类
社区版块
存档分类
最新评论

delete files using python

阅读更多
import os, sys,datetime,time
from stat  import *
path='c:\\test\\'
path2='c:\\test\\'
filelist=[]
filelist=os.listdir(path)
for i in range(len(filelist)):
        t1 = time.gmtime(os.stat(path+filelist)[ST_MTIME])  #get file's mofidy time
        t11 =  time.strftime('%Y-%m-%d',t1)
        year,month,day=t11.split('-')
        t111= datetime.datetime(int(year),int(month),int(day))       
        t2 = time.gmtime()
        t22 =  time.strftime('%Y-%m-%d',t2)
        year,month,day=t22.split('-')
        t222= datetime.datetime(int(year),int(month),int(day))       
        days =  (t222-t111).days
        if days>5 :  # if over 5 days then remove file
                try:
                        os.remove(path+filelist)
                        log=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+"  remove "+path+filelist+"  success \n"
                except:
                        log=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+"  remove "+path+filelist+"  fail \n"              
                fTemp=open(path2+"remove_file.log", 'a')       
                fTemp.write(log)
分享到:
评论

相关推荐

    Python高级编程_SQLite_Introduction to Programming Using Python

    在Python编程领域,SQLite是一个非常重要的数据库管理系统,尤其适合于小型、嵌入式应用或作为初学者学习数据库操作的工具。本主题将深入探讨如何在Python中使用SQLite进行高效的数据存储和检索。 SQLite是一个轻量...

    Hotel Management System Using Python.zip

    本项目“Hotel Management System Using Python”旨在利用Python这一强大的编程语言,构建一个高效、便捷的酒店管理系统,以提升酒店运营效率和服务质量。Python因其简洁易懂的语法和丰富的库支持,成为开发此类系统...

    Simple Member Registration System using Python

    需要了解如何创建数据库、表,执行SQL查询(如INSERT、SELECT、UPDATE和DELETE)以及连接和关闭数据库。 6. **表单验证**:为了保证数据质量,注册系统应包含数据验证。例如,检查电子邮件地址是否符合标准格式,...

    用python写代码删除文件 pyinstaller -F -w delete-folder11-all-files.py

    记得输入pyinstaller -F -w delete_folder11_all_files.py 就可以生成exe执行文件了。 用python写代码删除文件, 记得输入pyinstaller -F -w delete_folder11_all_files.py 就可以生成exe执行文件了。 用python写...

    Python库 | git_delete_merged_branches-1.0.0-py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:git_delete_merged_branches-1.0.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Simple Calculator App using Tkinter in Python

    这个"Simple Calculator App using Tkinter in Python"项目是一个基础的计算器应用,它利用Tkinter库来设计用户界面,并实现基本的计算功能,如加、减、乘、除。下面将详细介绍如何使用Tkinter构建这样的应用。 ...

    shell脚本调用python脚本,并传参

    例如,如果我们有一个名为`delete_files.py`的`Python`脚本,我们可以这样调用它: ```bash python3 /path/to/delete_files.py arg1 arg2 ``` 这里的`arg1`和`arg2`是传递给`Python`脚本的参数。在`Python`脚本中...

    每天分享几个python项目 —— simple-phone-contact-system-using-python.zip

    标题中的“simple-phone-contact-system-using-python.zip”是一个Python项目,主要目标是构建一个简单的电话联系管理系统。这个系统可能包括添加、删除、查找和显示联系人的功能,是学习Python后端开发的一个基础...

    delete_empty_files.zip

    标题 "delete_empty_files.zip" 提供的是一个 Python3 实现的程序,用于删除所有空文件夹,同时还包含了一个图形化界面。这个程序的亮点在于它非递归地扫描并删除空目录,对于理解和实践文件系统操作是很有帮助的。...

    Python界面版学生系统,python学生管理系统界面版,Python

    这些库允许程序连接到远程或本地的MySQL服务器,执行CRUD(Create, Read, Update, Delete)操作来管理学生数据。 虽然当前的系统缺少登录界面,但在实际应用中,登录验证是必不可少的。登录界面用于确保只有授权的...

    Python库 | Files.com-1.0.191-py3-none-any.whl

    Files.com库的API通常包括一系列方法,如`list`用于获取目录内容,`upload`用于上传文件,`download`用于下载文件,以及`move`、`copy`、`delete`等用于文件和目录的操作。开发者可以根据需求选择相应的方法进行调用...

    python find file and del

    def delete_py_files(start_dir): for root, dirs, files in os.walk(start_dir): for file in files: if file.endswith('.py'): file_path = os.path.join(root, file) delete_file(file_path) # 使用示例 ...

    python简单的银行管理系统

    需要掌握如何创建数据库、表,执行SQL查询(如INSERT、SELECT、UPDATE、DELETE),以及如何通过Python代码操作数据库。 4. **异常处理**:在处理用户输入和银行交易时,我们需要对可能出现的错误进行处理,比如存款...

    从C++导出类到Python

    {"deleteCppClass", deleteCppClass, METH_O, "Delete a C++ class instance."}, {"cplusplusMethod", cplusplusMethod, METH_VARARGS, "Call a C++ method."}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC PyInit...

    Inventory Management System in Python using Django

    product = models.ForeignKey(Product, on_delete=models.CASCADE) quantity = models.IntegerField() last_updated = models.DateTimeField(auto_now=True) ``` 2. 数据库迁移:模型定义后,运行`python manage....

    Simple Polling System in Python using Django Framework

    question = models.ForeignKey(Question, on_delete=models.CASCADE) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) ``` 5. **数据库迁移**: 运行`python manage.py ...

    Python火车票管理系统源码.zip

    在Python中,可以使用SQLite3的DELETE语句删除特定的购票记录,并通过UPDATE语句更新座位状态。 此外,用户界面(UI)也是系统的重要组成部分。Python的Tkinter库或PyQt等图形用户界面库可以用来创建直观易用的界面...

    python面向对象课件

    Python的访问控制通过描述符协议实现,描述符是实现了`__get__`、`__set__`和`__delete__`方法的类。描述符可以用来实现属性的特殊行为,如属性缓存、验证或计算属性。 通过深入学习这些知识点,并结合课件中的实例...

    Python爬虫下载磁力链接

    Python 爬虫下载磁力链接 【知识点详解】 1. 磁力链接(Magnet URI Scheme) 磁力链接是一种用于标识资源的链接,它不同于传统的 HTTP 链接,而是以"magnet:"开头,后面跟着一段 base32 编码的字符串。磁力链接的...

    slack-delete-files:使用JavaScript从Slack批量删除文件

    $ npm install -g slack-delete-files 除了污染全局安装之外,您还可以直接运行Node二进制文件: $ npx slack-delete-files 用法 $ slack-delete-files Options: --help Show help [boolean] --version Show ...

Global site tag (gtag.js) - Google Analytics