python将指定文件夹下的文件类型复制到另一个文件夹

使用的库 shutil,os

	import shutil,os

创建文件夹

try:
    os.makedirs('_Gen/Includes')
except FileExistsError:
    pass

搜索指定目录下的制定文件类型

#搜索头文件
def file_name(file_dir):
    L = []
    for root,dirs,files in os.walk(file_dir):
        for file in files:
            if os.path.splitext(file)[1] == '.h':
                L.append(os.path.join(root,file))
    return L

将文件复制到指定文件夹

#复制H文件
def copy_H_File(file_list):
  for list1 in file_list:
      #复制头文件
      shutil.copy(list1, '_Gen/Includes') 

函数调用

f = file_name("../Asw")
copy_H_File(f)

大功告成
欢迎搭建关注我的gitee库:
https://gitee.com/clipping

猜你喜欢

转载自blog.csdn.net/qq_44992918/article/details/123363701