好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

代码

import owww.cppcns.coms
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:
  prhttp://www.cppcns.comint("take{}from{}".format(file, files))
  dir = path + '/' + file # 存储文件路径
  deter = tar_path + '/' + str(file)
  shutil.copyfile(dir, deter)


if _ http://www.cppcns.com _name__ == "__main__":
 take_samefile(r"", r"", "")

运行结果

运行前(原始文件夹)

运 aaqmJbvp 行过程

运行后

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

查看更多关于python实现批量提取指定文件夹下同类型文件的详细内容...

  阅读:37次