python拷贝图片

 

 python拷贝图片_第1张图片

 

import os
import shutil
import tqdm

old_path = 'D:\\Codeware\\Pythoncode\\picture\\test_pic'
new_path = 'D:\\Codeware\\Pythoncode\\picture\\save_pic'

files = os.listdir(old_path)
for i in tqdm.tqdm(range(len(files))):
    # print(files[i][0:36])
    # print(files[i][0:36])
    if ( i>=1 and files[i][-3:] == 'jpg' and files[i][0:36] !=files[i-1][0:36] ):
        #print(files[i][0:36])
        # 格式jpg转为png
        old_file_path = old_path + '//' + files[i]
        new_file_path = new_path + '//' + files[i][:-3]+'png'
        shutil.copy(old_file_path, new_file_path)
    elif i==0:
        old_file_path = old_path + '//' + files[i]
        new_file_path = new_path + '//' + files[i][:-3]+'png'
        shutil.copy(old_file_path, new_file_path)

你可能感兴趣的:(python,开发语言)