当前位置:首页 » python教程 » 正文

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

看: 939次  时间:2021-05-21  分类 : 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博客。

标签:pandas  

<< 上一篇 下一篇 >>

搜索

推荐资源

  Powered By python教程网   鲁ICP备18013710号
python博客 - 小白学python最友好的网站!