title: Rename the subdirectories in python
body: <p>I have a directory called <code>data</code>, that contains several <code>folders/sub-folders</code> like below;</p>
  
  <pre><code>/training/07-21-2016-ABCD-67862/1-ROI regi images-08456/1.png
  /training/08-11-2017-AESD-66874/2-ROI regi images-06521/2.png
  -
  -
  </code></pre>
  
  <p>I want to rename the folders/sub-folders like below;</p>
  
  <pre><code>/training/67862/08456/1.png
  /training/66874/06521/2.png
  -
  -
  </code></pre>
  
  <p>note that I keep only the last 5 digits in the sub-folders as shown above (no name change in the <strong>training folder</strong>). How do I achieve this in python?
  This is what I did;</p>
  
  <pre><code>temp = os.walk(test_path, topdown=False)
  for root, dirs, files in temp:
      for i in dirs:
          dir = os.path.join(root,i)
  
          os.rename(dir, dir[-5:]) # get only the last five digits.
  </code></pre>
  
  <p>But I am not getting the desired output. </p>