title: Adding an index to file and directory names
body: <p>I'm having a little brainfreeze here.</p>
  
  <p>I want to add an index to the files and directories. I've tried so many different solutions 
  that I finally decided to turn to the community for some pointers.</p>
  
  <p>When traversing the tree directory A-1.1 is assigned index of 2 instead of 1.1, as it is the second directory os.walk enters.</p>
  
  <p>I am doing this to save our secretaries at work countless hours of renaming files/directories.
  Any help much appreciated.</p>
  
  <p>If someone wants to give it a try here's the test directory tree :</p>
  
  <p><a href="https://drive.google.com/open?id=1EoBzVPFOvixMlCdWWlUgucMd5zunI20U" rel="nofollow noreferrer">https://drive.google.com/open?id=1EoBzVPFOvixMlCdWWlUgucMd5zunI20U</a></p>
  
  <p>As I was told download takes ages, here's zipped version : </p>
  
  <p><a href="https://drive.google.com/open?id=1I-1LKk2FRIVm9Tp2I9bYQOCOemV07jQr" rel="nofollow noreferrer">https://drive.google.com/open?id=1I-1LKk2FRIVm9Tp2I9bYQOCOemV07jQr</a></p>
  
  <p>The embarrassing code:</p>
  
  <pre><code>import os
  rootDir = "/.../root"
  rootIndex = 1
  
  for dirName, subdirList, fileList in sorted(os.walk(rootDir)):
  
     subindex = 1
  
     print(f'DIR : {rootIndex} - {dirName}')
  
     for fname in fileList:
         print(f'file :: {rootIndex}.{subindex} - {fname}')
         subindex = subindex + 1
  
  ### This cannot work properly as it increases the rootIndex whenever it encounters empty dir
     if not subdirList:
         print(f'End')
         rootIndex = rootIndex + 1
  </code></pre>
  
  <p>The tree looks like this, with hardcoded desired result to keep track of it.</p>
  
  <pre><code>├── A-1
  │   ├── A-1.1
  │   │   ├── file-A-1.1.1.txt
  │   │   ├── file-A-1.1.2.txt
  │   │   ├── file-A-1.1.3.txt
  │   │   ├── file-A-1.1.4.txt
  │   │   └── file-A-1.1.5.txt
  │   ├── A-1.2
  │   │   ├── file-A-1.2.1.txt
  │   │   ├── file-A-1.2.2.txt
  │   │   ├── file-A-1.2.3.txt
  │   │   ├── file-A-1.2.4.txt
  │   │   └── file-A-1.2.5.txt
  │   └── A-1.3
  │       ├── A-1.3.1
  │       │   ├── file-A-1.3.1.1.txt
  │       │   ├── file-A-1.3.1.2.txt
  │       │   ├── file-A-1.3.1.3.txt
  │       │   ├── file-A-1.3.1.4.txt
  │       │   └── file-A-1.3.1.5.txt
  │       └── A-1.3.2
  │           ├── file-A-1.3.2.1.txt
  │           ├── file-A-1.3.2.2.txt
  │           ├── file-A-1.3.2.3.txt
  │           ├── file-A-1.3.2.4.txt
  │           └── file-A-1.3.2.5.txt
  └── B-2
  ├── B-2.1
  │   ├── file-B-2.1.1.txt
  │   ├── file-B-2.1.2.txt
  │   ├── file-B-2.1.3.txt
  │   ├── file-B-2.1.4.txt
  │   └── file-B-2.1.5.txt
  └── B-2.2
  ├── B-2.2.1
  │   ├── file-B-2.2.1.1.txt
  │   ├── file-B-2.2.1.2.txt
  │   ├── file-B-2.2.1.3.txt
  │   ├── file-B-2.2.1.4.txt
  │   └── file-B-2.2.1.5.txt
  ├── B-2.2.2
  │   ├── file-B-2.2.2.1.txt
  │   ├── file-B-2.2.2.2.txt
  │   ├── file-B-2.2.2.3.txt
  │   ├── file-B-2.2.2.4.txt
  │   └── file-B-2.2.2.5.txt
  ├── file-B-2.2.3.txt
  ├── file-B-2.2.4.txt
  ├── file-B-2.2.5.txt
  ├── file-B-2.2.6.txt
  └── file-B-2.2.7.txt
  </code></pre>