python文件复制操作。

 1 # -*- coding: utf-8 -*-
 2 import shutil
 3 import os
 4 # file_path = 'C:\\Users\\WT\\Desktop\\001.jpg'
 5 # new_path = 'C:\\Users\\WT\\Desktop\\new.jpg'
 6 # path = shutil.copy(file_path, new_path)
 7 # print(path)
 8
 9 def copy_file(finddir,fromdir, todir):
10     num = 0
11     list = os.listdir(finddir)
12     for i in range(0, len(list)):
13         if list[i][-3:] == 'res':
14             if len(list[i]) == 11:
15                 from_path = fromdir + '\\' + list[i][:-7]
16             else:
17                 from_path = fromdir + '\\0' + list[i][:-7]
18             #from_path = fromdir + '\\0' + list[i][:-7]
19             fromlist = os.listdir(from_path)
20             for j in range(0, len(fromlist)):
21                 if list[i][:-4] == fromlist[j][:-4]:
22                     from_fullpath = from_path + '\\'+ fromlist[j]
23                     to_path = todir + '\\'+ fromlist[j]
24                     path = shutil.copy(from_fullpath, to_path)
25                     print(path)
26                     num = num + 1
27                     print(num)
28
29
30
31 if __name__ == '__main__':
32     copy_file('D:\\idcard_images\\服务器端\\1-30文件夹分析\\车辆识别代号字段\\标准答案错误',
33               'F:\\云端行驶证定位调整\\行驶证三调发动机号码\\生成识别结果\\服务器\\03 手机拍照\\01 自由拍照',
34               'C:\\Users\\WT\\Desktop\\tmp')
12-17 01:28