title: Walk a folder structure, rename files to match sub-folder, keep file extension
body: <p>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.</p>
  
  <p>Example folder structure:</p>
  
  <pre><code>root folder
  ├── first sub-folder (Batman)
  │   ├── filename.extension (joker.pdf)
  │   └── filename.differentExtension (bane.jpg)
  │
  └── second sub-folder
      ├── filename.extension
      └── filename.differentExtension
  </code></pre>
  
  <p>So after the script has completed, the result would look like the below:</p>
  
  <pre><code>root folder
  ├── first sub-folder (Batman)
  │   ├── filename.extension (Batman.pdf)
  │   └── filename.differentExtension (Batman.jpg)
  │
  └── second sub-folder
      ├── filename.extension
      └── filename.differentExtension
  </code></pre>
  
  <p>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.</p>