#复制文件函数
def copy_files(l,dd):
for n in range(len(dd)):
d=re.findall(r'/(.*)/', dd.loc[n,'image file path'])[0]
a=re.findall(r'/(.*)', d)[0]
old_path=f"D:/archive/jpeg/{a}"
full_filenames=os.listdir(old_path)
os.makedirs(f"d:/images/{n+l}")
for i in full_filenames:
shutil.copy(f"{old_path}/{i}", f'd:/images/{n+l}/full_{n+l}.jpg')
d=re.findall(r'/(.*)/', dd.loc[n,'cropped image file path'])[0]
a=re.findall(r'/(.*)', d)[0]
old_path=f"D:/archive/jpeg/{a}"
if os.path.exists(old_path):
cropped_filenames=os.listdir(old_path)
for i in cropped_filenames:
if i[0]=='1':
shutil.copy(f"{old_path}/{i}", f'd:/images/{n+l}/cropped_{n+l}.jpg')
else:
shutil.copy(f"{old_path}/{i}", f'd:/images/{n+l}/roi_{n+l}.jpg')
# dd=pd.read_csv('D:/archive/csv/dicom_info.csv')
# info=dd[['image_path','PatientName']]
dd=pd.read_csv('D:/archive/csv/calc_case_description_test_set.csv')
copy_files(0,dd)
l=len(dd)
dd=pd.read_csv('D:/archive/csv/calc_case_description_train_set.csv')
copy_files(l,dd)
l=l+len(dd)
dd=pd.read_csv('D:/archive/csv/mass_case_description_test_set.csv')
copy_files(l,dd)
l=l+len(dd)
dd=pd.read_csv('D:/archive/csv/mass_case_description_train_set.csv')
copy_files(l,dd)