Python-快速提取文件夹中各个子文件夹中所有文件并复制到新文件夹

发布于 2023-05-08  337 次阅读


Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------

例如:Endnote 存储的PDF文件夹中每个文献都单独存储在一个子文件夹中,快速一次提取所有pdf文件到一个新的文件夹。 其他类型.jpg等同理。

# -*- coding: utf-8 -*-
"""Yuwei Feng"""

import os
import shutil
file_path = "C://Users\AQ84510\YuweiWorkdata\PDF"  # 文件夹路径
out_path = "C://Users/AQ84510/YuweiWorkdata/PaperMayAll"  #输出文件夹路径

# i = 0
for dirpath, dirnames, filename in os.walk(file_path):
    #print(dirpath,'\n', dirnames,'\n', filename)    
    file_list = os.listdir(dirpath) #file name
    for file in file_list:
        if file.endswith('.pdf'):
            shutil.copy(os.path.join(dirpath, file), os.path.join(out_path, file + '.pdf'))
届ける言葉を今は育ててる
最后更新于 2023-05-08