《运维日常》持续更新中
使用Python编写的多线程快速批量删除文件的脚本
以下是使用Python编写的多线程快速批量删除文件的脚本示例:
import os
import threading
def delete_files(file_list):
for file_path in file_list:
try:
os.remove(file_path)
print(f"Deleted file: {file_path}“)
except OSError as e:
print(f"Error deleting file: {file_path} - {e}”)
def batch_delete_files(directory, file_extension):
file_list = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(file_extension):
file_path = os.path.join(root, file)
file_list.append(file_path)
设置线程数,根据需要进行调整
num_threads = 4
每个线程处理的文件数量
files_per_thread = len(file_list) // num_threads
创建线程列表
threads = []
for i in range(num_threads):
start_index = i * files_per_thread
end_index = start_index + files_per_thread if i < num_threads - 1 else len(file_list)
thread_files = file_list[start_index:end_index]
thread = threading.Thread(target=delete_files, args=(thread_files,))
threads.append(thread)
启动线程
for thread in threads:
thread.start()
等待所有线程完成
for thread in threads:
thread.join()
print(“All files deleted.”)
示例用法
directory = “/path/to/directory” # 要删除文件的目录
file_extension = “.txt” # 要删除的文件扩展名
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数软件测试工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年软件测试全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上软件测试开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注软件测试)
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**