网络编程
位置:首页>> 网络编程>> Python编程>> python实现批量提取指定文件夹下同类型文件

python实现批量提取指定文件夹下同类型文件

作者:劲酒奶奶  发布时间:2023-11-17 17:13:31 

标签:python,提取文件

本文通过实例为大家分享了python实现批量提取指定文件夹下同类型文件,供大家参考,具体内容如下

代码


import os
import shutil

def take_samefile(or_path, tar_path, tar_type):
tar_path = tar_path
if not os.path.exists(tar_path):
os.makedirs(tar_path)
path = or_path
files = os.listdir(path) # 读取or_path文件列表
for file in files:
file_type = str(file).split('.')[1] # 读取文件后缀
if file_type == tar_type:
 print("take{}from{}".format(file, files))
 dir = path + '/' + file # 存储文件路径
 deter = tar_path + '/' + str(file)
 shutil.copyfile(dir, deter)

if __name__ == "__main__":
take_samefile(r"", r"", "")

运行结果

运行前(原始文件夹)

python实现批量提取指定文件夹下同类型文件

运行过程

python实现批量提取指定文件夹下同类型文件

运行后

python实现批量提取指定文件夹下同类型文件

来源:https://blog.csdn.net/qq_44813407/article/details/115412621

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com