title: Rename part of filenames in sub-folders python
body: <p>I have to rename images in main directory with contains sub-folders, script with I using right now do some work but not exactly what I need: I can't find a way to do it properly, now i have it:</p>
  
  <pre><code>maindir #my example origin
  ├── Sub1
  │   ├── example01.jpg
  │   ├── example02.jpg
  │   └── example03.jpg
  └── Sub2
      ├── example01.jpg
      ├── example02.jpg
      └── example03.jpg
  </code></pre>
  
  <p>My script do that:</p>
  
  <pre><code>maindir
  ├── Sub1
  │   ├── Sub1_example01.jpg
  │   ├── Sub1_example02.jpg
  │   └── Sub1_example03.jpg
  └── Sub2
      ├── Sub2_example01.jpg
      ├── Sub2_example02.jpg
      └── Sub2_example03.jpg
  </code></pre>
  
  <p>And I would like to get it :replace a letters in my filenames by my sub-folder name and keep the origin numbers of my jpg:</p>
  
  <pre><code>maindir
  ├── Sub1
  │   ├── Sub1_01.jpg
  │   ├── Sub1_02.jpg
  │   └── Sub1_03.jpg
  └── Sub2
      ├── Sub2_01.jpg
      ├── Sub2_02.jpg
      └── Sub2_03.jpg
  </code></pre>
  
  <p>there is my code 4 witch I using:</p>
  
  <pre><code>from os import walk, path, rename
  parent = ("F:\\PS\\maindir")
  for dirpath, _, files in walk(parent):
      for f in files:
          rename(path.join(dirpath, f), path.join(dirpath, path.split(dirpath)[-1] + '_' + f))
  </code></pre>
  
  <p>what I have to change overhere to get my result???</p>