I'm using the pathlib library to handle I/O in my script. I read a file with the path:
PosixPath('input/ADE/data_f34.dat')
The parent folder input/ is fixed, but neither the sub-folder (ADE) nor the file's name are fixed, i.e., they change with each iteration. I need a general to store a new file with the same name, to the path:
PosixPath('output/ADE/data_f34.dat')
I.e., respecting the sub-folder and the file's names, but changing input/ to output/. The output folder always exists, but I don't know a priori if the sub-folder output/ADE/ exists so I need to create if it does not. If a file with the same name already exists, I can simply overwrite it.
What is the proper way to handle this with pathlib?