I am working on a project that requires me to download images into sub directories. Instead of writing my own code, I elected to use code that is already available for the sake of time. However, I'm running into a slight problem with creating directory if directory does not exist.
After some extensive troubleshooting, I notice the images are not saving in the appropriate folders. This is happening even if the folders exist in the path. In short, the images are not saving in the nested directory.
Is is possible to create sequential nested directories with os.makedirs
?
for example:
kits19process\Image\0\img1.png
kits19process\Image\1\img1.png
kits19process\Image\2\img1.png
I also tried using os.makedirs(tumorimagefile, exist_ok=True)
as well. But that technique raised an error.
I have hunch that the problem lies here. I may be wrong, so here is the link to the full script.
trainimagefile = proImage + str(seriesindex)
trainMaskfile = proMask + str(seriesindex)
if not os.path.exists(trainimagefile):
os.makedirs(trainimagefile)
if not os.path.exists(trainMaskfile):
os.makedirs(trainMaskfile)
tumorimagefile = protumorImage + str(seriesindex)
tumorMaskfile = protumorMask + str(seriesindex)
if not os.path.exists(tumorimagefile):
os.makedirs(tumorimagefile)
if not os.path.exists(tumorMaskfile):
os.makedirs(tumorMaskfile
Also here is a screenshot of what is happening when I run this code (incorrect way).
]1).
As you can see the files are not saving into the correct folders.
I expect the actual output is to have the images and mask saved in the appropriate folders.
data/
Kits19/
kits19process/
Image/
0/
0.bmp
Mask/
0/
0.bmp
kits19tumorprocess/
Image/
0/
0.bmp
Mask/
0/
0.bmp