import os import time import sys from xml.dom import minidom, Node from xml.dom.minidom import parse,parseString from stat import * import xml.etree.ElementTree as ET #删除1day前的日志 def DelLog(filepath): if not os.path.isdir(filepath) and not os.path.is
python脚本 删除2天前后缀为.log的文件 #!/usr/local/python/bin/python #-*-coding=utf8 -*- import time import os,sys N = 2 #设置删除多少天前的文件 def deletefile(path): for eachfile in os.listdir(path): filename = os.path.join(path,eachfile) if os.path.isfile(filename): lastm
一个目录下有文件,文件夹,文件夹里又有文件.文件夹....用python脚本,实现,递归删除一个目录下的所有文件: 目录结构如下: 其中我们要删除所有文件 代码实现如下: import os CUR_PATH = r'C:\Users\shenping\PycharmProjects\Shenping_TEST\day_5\Testfolder' def del_file(path): ls = os.listdir(path) for i in ls: c_path = os.path.joi
先放一个python遍历发生的异常: ls =[1,2,3,4,5,6,7,8,9] for i in ls: print("i",i) print("ls",ls) ls.remove(i) 运行结果: i 1 ls [1, 2, 3, 4, 5, 6, 7, 8, 9] i 3 ls [2, 3, 4, 5, 6, 7, 8, 9] i 5 ls [2, 4, 5, 6, 7, 8, 9] i 7 ls [2, 4, 6, 7, 8, 9] i 9 ls [2,