python-windows清理指定路径下的日志文件

 

清除对应路径文件夹内的文件,配上windows定时任务,可以设置定时清理

import os

def cleanpath(cpath):
  os.remove(cpath) 

#要清空文件夹
dirpath =['C:\\Hundsun\\log\\Hshqserverlhqlog','C:\\Hundsunl\\Hshqserver\\Dump']

n=0  
t=[]
while n < len (dirpath):
  for root,dirs,files in os.walk(dirpath[n]):
    for file in files:
    if file not in t:
      t.append (os.path.join(root, file))
n=n+1

i=0
while i < len(t):
  cleanpath(t[i]) 
  i=i+ 1

 

posted @ 2022-07-04 17:10  小胡要加油  阅读(107)  评论(0编辑  收藏  举报