title: batch renaming 100K files with python
body: <p>I have a folder with over 100,000 files, all numbered with the same stub, but without leading zeros, and the numbers aren't always contiguous (usually they are, but there are gaps) e.g:</p>
  
  <pre><code>file-21.png, 
  file-22.png,  
  file-640.png, 
  file-641.png, 
  file-642.png, 
  file-645.png, 
  file-2130.png, 
  file-2131.png, 
  file-3012.png, 
  </code></pre>
  
  <p>etc.</p>
  
  <p>I would like to batch process this to create padded, contiguous files. e.g:</p>
  
  <pre><code>file-000000.png, 
  file-000001.png, 
  file-000002.png, 
  file-000003.png, 
  </code></pre>
  
  <p>When I parse the folder with <code>for filename in os.listdir('.'):</code> the files don't come up in the order I'd like to them to. Understandably they come up </p>
  
  <pre><code> file-1, 
   file-1x, 
   file-1xx, 
   file-1xxx,
  </code></pre>
  
  <p>etc. then</p>
  
  <pre><code> file-2, 
   file-2x, 
   file-2xx, 
  </code></pre>
  
  <p>etc. How can I get it to go through in the order of the numeric value? I am a complete python noob, but looking at the docs i'm guessing I could use map to create a new list filtering out only the numerical part, and then sort that list, then iterate that? With over 100K files this could be heavy. Any tips welcome!</p>