内容涉及:路径拼接,文件拷贝,内容追加(append)
# !/usr/bin/python # -*- coding: UTF-8 -*- import pandas as pd import os import time import scipy.misc from shutil import copyfile from PIL import Image import shutil lossfile_csv = [] lossfile_img = [] for line in open("error.txt"): csvpath = line.strip('\n') arr = csvpath.split('/') arr_2 = arr[3] arr_split = arr_2.split('_') batch_Id = arr_split[0] Medical_Id = arr_split[1] FOV_Id = arr_split[2] csv_dir_path = './csv/' + batch_Id + '/' + Medical_Id + '/' + FOV_Id[:-3] + 'csv' csv_new_path = './data_error' + '/' + batch_Id + '_' + Medical_Id + '_' + FOV_Id[:-3] + 'csv' img_dir_path = './img/' + batch_Id + '/' + Medical_Id + '/' + 'Images/' + FOV_Id img_new_path = './data_error' + '/' + batch_Id + '_' + Medical_Id + '_' + FOV_Id if not os.path.exists(csv_dir_path): print("not exit file:",csv_dir_path) lossfile_csv.append(csv_dir_path) continue if not os.path.exists(img_dir_path): print("not exit file:",img_dir_path) lossfile_img.append(img_dir_path) continue shutil.copy(csv_dir_path,csv_new_path) shutil.copy(img_dir_path,img_new_path) print("END")