python之文件复制

时间:2021-08-05 08:55:49

python文件复制操作。

 # -*- coding: utf-8 -*-
import shutil
import os
# file_path = 'C:\\Users\\WT\\Desktop\\001.jpg'
# new_path = 'C:\\Users\\WT\\Desktop\\new.jpg'
# path = shutil.copy(file_path, new_path)
# print(path) def copy_file(finddir,fromdir, todir):
num = 0
list = os.listdir(finddir)
for i in range(0, len(list)):
if list[i][-3:] == 'res':
if len(list[i]) == 11:
from_path = fromdir + '\\' + list[i][:-7]
else:
from_path = fromdir + '\\0' + list[i][:-7]
#from_path = fromdir + '\\0' + list[i][:-7]
fromlist = os.listdir(from_path)
for j in range(0, len(fromlist)):
if list[i][:-4] == fromlist[j][:-4]:
from_fullpath = from_path + '\\'+ fromlist[j]
to_path = todir + '\\'+ fromlist[j]
path = shutil.copy(from_fullpath, to_path)
print(path)
num = num + 1
print(num) if __name__ == '__main__':
copy_file('D:\\idcard_images\\服务器端\\1-30文件夹分析\\车辆识别代号字段\\标准答案错误',
'F:\\云端行驶证定位调整\\行驶证三调发动机号码\\生成识别结果\\服务器\\03 手机拍照\\01 *拍照',
'C:\\Users\\WT\\Desktop\\tmp')