- #coding=utf-8
-
- import os
- import pathlib
- import re
- import shutil
- # import gol
-
- def check_dir(des_path):
- my_dir = pathlib.Path(des_path)
- if my_dir.is_dir():
- return 0
- else:
- print('{}目录不存在\n正在创建文件夹')
- os.mkdir(des_path)
-
- #搜索文件目录
- test_path = r'd:\gin\c'
- #复制到指定目录
- des_path = r'd:\gin\test_16'
-
- #存储文件
- _clist = []
- temp = []
-
- if check_dir(des_path) == 0: print('[{}]目录已经存在'.format(des_path))
- else: check_dir(des_path)
-
- for root,dirs,files in os.walk(test_path):
- # print('当前目录为:',root)
- # print('当前目录下的子目录为:',dirs)
- for each_file in files:
- #将以.c结尾的文件添加到列表
- temp=re.findall('.*\.c,os.path.join(root,each_file))
- if temp != []: _clist.append(temp)
-
- # os.chdir(des_path)
- for each_file in _clist:
- print('copy :',*each_file,'--->',des_path)
- #复制文件
- shutil.copy(*each_file,des_path)
-
- print('Done!')
复制代码
|