title: How to rename path name?
body: <p>I have <code>.dcm</code> files in a path like below <code>(old_path)</code>;</p>
  
  <pre><code>old_path: Mass-Test_P_00016_LEFT_MLO_1/10-04-2016-DDSM-15563/1-cropped images-77287/000000.dcm
  </code></pre>
  
  <p>I have to rename the path like below <code>(good_path)</code>;</p>
  
  <pre><code>good_path: Mass-Test_P_00016_LEFT_MLO_1/15563/77287/000000.dcm
  </code></pre>
  
  <p>Note that I keep only the last 5 digits in the sub-folders as shown above.</p>
  
  <p>Please anyone show me how this must be done?
  This is my attempt...</p>
  
  <pre><code>os.chdir(path to data)
  os.listdir()
  &gt;&gt; ['Mass-Test_P_00016_LEFT_MLO_1', 'Mass-Test_P_00016_LEFT_MLO']
  
  temp = os.walk('Mass-Test_P_00016_LEFT_MLO_1', topdown=False)
  for root, dirs, files in temp:
      for name in files:
          old_path = os.path.join(root, name)
          print("old_path: ", old_path)
          first = old_path.split('/')[1][-5:]
          second = old_path.split('/')[2][-5:]
          #print(first, second)
          good_path = os.path.join(old_path.split('/')[0], first, second, old_path.split('/')[3])
          print("good_path: ", good_path)
          os.rename(old_path, good_path)  
  </code></pre>
  
  <p>I was able to set the <code>good_path</code> as I want. But it is not overwriting the <code>subfolders</code> names.</p>