I am new to python and coding, as a first project, I am looking to create a python script which will traverse a folder structure and look inside each sub-folder and rename the files within to match the name of the sub-folder.
Example folder structure:
root folder
├── first sub-folder (Batman)
│ ├── filename.extension (joker.pdf)
│ └── filename.differentExtension (bane.jpg)
│
└── second sub-folder
├── filename.extension
└── filename.differentExtension
So after the script has completed, the result would look like the below:
root folder
├── first sub-folder (Batman)
│ ├── filename.extension (Batman.pdf)
│ └── filename.differentExtension (Batman.jpg)
│
└── second sub-folder
├── filename.extension
└── filename.differentExtension
I am looking for recommendations into how to approach this, I was thinking of using os.path.splitext to seperate the filename from the file extension, but i'm unsure how to change the filename to the sub-folder value and then concatenate the filename and file extension back together.

