When i run the code
directory_to_move = "PATIENT_DICOM"
desired_scans_path = os.path.join("train", "patients")
desired_masks_path = os.path.join("train", "masks")
try:
os.mkdir("train")
except OSError as error:
print(error)
try:
os.mkdir(desired_scans_path)
except OSError as error:
print(error)
for patient_path in os.listdir(dataset_path):
patient_full_path = os.path.join(dataset_path, patient_path)
if os.path.isdir(patient_full_path):
patient_scans_path = os.path.join(patient_full_path, "PATIENT_DICOM")
if os.path.isdir(patient_scans_path):
for scan in os.listdir(patient_scans_path):
os.rename(os.path.join(patient_scans_path, scan), os.path.join(desired_scans_path, scan))
try:
os.mkdir(desired_masks_path)
except OSError as error:
print(error)
for patient_path in os.listdir(dataset_path):
patient_full_path = os.path.join(dataset_path, patient_path)
if(os.path.isdir(patient_full_path)):
patient_masks_path = os.path.join(patient_full_path, "MASKS_DICOM")
if os.path.isdir(patient_masks_path):
for scan in os.listdir(patient_masks_path):
os.replace(os.path.join(patient_masks_path, scan), os.path.join(desired_masks_path, scan))
try:
os.mkdir(os.path.join(desired_masks_path, "merged_livertumors"))
except OSError as error:
print(error)
I get this error
[WinError 183] Cannot create a file when that file already exists: 'train'
[WinError 183] Cannot create a file when that file already exists: 'train\patients'
[WinError 183] Cannot create a file when that file already exists: 'train\masks'
[WinError 183] Cannot create a file when that file already exists: 'train\masks\merged_livertumors'
When i run the code directory_to_move = "PATIENT_DICOM" desired_scans_path = os.path.join("train", "patients") desired_masks_path = os.path.join("train", "masks") try:
os.mkdir("train")
except OSError as error:
print(error)
try:
os.mkdir(desired_scans_path)
except OSError as error:
print(error)
for patient_path in os.listdir(dataset_path): patient_full_path = os.path.join(dataset_path, patient_path) if os.path.isdir(patient_full_path): patient_scans_path = os.path.join(patient_full_path, "PATIENT_DICOM") if os.path.isdir(patient_scans_path): for scan in os.listdir(patient_scans_path): os.rename(os.path.join(patient_scans_path, scan), os.path.join(desired_scans_path, scan))
try:
os.mkdir(desired_masks_path)
except OSError as error:
print(error)
for patient_path in os.listdir(dataset_path): patient_full_path = os.path.join(dataset_path, patient_path) if(os.path.isdir(patient_full_path)): patient_masks_path = os.path.join(patient_full_path, "MASKS_DICOM") if os.path.isdir(patient_masks_path): for scan in os.listdir(patient_masks_path): os.replace(os.path.join(patient_masks_path, scan), os.path.join(desired_masks_path, scan))
try:
os.mkdir(os.path.join(desired_masks_path, "merged_livertumors"))
except OSError as error:
print(error)
I get this error
[WinError 183] Cannot create a file when that file already exists: 'train' [WinError 183] Cannot create a file when that file already exists: 'train\patients' [WinError 183] Cannot create a file when that file already exists: 'train\masks' [WinError 183] Cannot create a file when that file already exists: 'train\masks\merged_livertumors'