首页 > 其他 > 详细

OS9000批量删除小文件

时间:2020-04-23 16:53:32      阅读:59      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/python

# -*- coding: utf-8 -*-
# @Author : moshell
# @Date : 2020/4/3

import os
import random
import logging
import toml
from concurrent.futures import ThreadPoolExecutor

class DeleteData(object):
def __init__(self):
self.basicConfig=logging.basicConfig(
level=logging.INFO,
format=‘%(levelname)s[%(asctime)s]:%(message)s‘,
filemode=‘r‘,
)
self.path="/data66/v1/queue/{}"
def go(self):
with open("./config.toml","r",encoding="utf-8") as f:
toml_file_tmp = toml.load(f)
threads=toml_file_tmp.get("threads").get("threads")
pool = ThreadPoolExecutor(threads)
#input_date = input("请输入需要删除日期(格式:20200101)>>>:").strip()
with open("./config.toml", "r", encoding="utf-8") as f:
toml_file = toml.load(f)
dates_list=toml_file.get("dates").get("dates")
for input_date in dates_list:
dir_list = os.listdir(self.path.format(input_date))
for dirs in dir_list:
dirs_path=os.path.join(self.path.format(input_date),dirs)
for gob_file in os.listdir(dirs_path):
num = random.randint(36, 82)
del_file_name = os.path.join("/data{}/v1/queue/{}/{}/{}".format(
num,input_date, dirs, gob_file
))
self.handle(del_file_name)
pool.submit(self.handle,del_file_name)

def handle(self,del_file):
logging.info("开始删除{}...".format(del_file))
os.system("rm -rf {}".format(del_file))
logging.info("{}已删除...".format(del_file))

if __name__=="__main__":
node=DeleteData()
node.go()

OS9000批量删除小文件

原文:https://www.cnblogs.com/moshell/p/12761734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!