title: Python - Add leading 0 to file numbers
body: <p>I am new to python and programming generally
  I have 1200 text files in a folder, in the following format:<br>
  James - 1 - How to... .txt<br>
  Sarah - 2 - How to... .txt<br>
  Steph - 3 - How to... .txt<br>
  ...<br>
  Mariah - 200 - How to... .txt<br>
  ...<br>
  Rashford - 1200 - How to... .txt<br></p>
  
  <p>I want to rename the files below 1000 to add leading 0's so they all have the same number of digits, for instance, 0001, 0050, 0300</p>
  
  <p>This is my code so far, but am stuck:</p>
  
  <pre><code>#!python3
  
  import os
  from tkinter import filedialog
  
  cleaned_files = []
  
  root_folder = filedialog.askdirectory()
  os.chdir(root_folder)
  folder_files = os.listdir(root_folder)
  
  # Filter out files starting with '.' and '_'
  cleaned_files = []
  for item in folder_files:
      if item[0] == '.' or item[0] == '_':
          pass
      else:
          cleaned_files.append(item)
  
  
  # Find file names of the root folder and save them
  
  
  def getFiles(files):
      for file in files:
          file_start, file_number, file_end = file.split('-')
          file_number.strip()
  
          # Was trying to append just one 0 to numbers &lt;10
          if int(file_number) &lt; 10:
              print(file_number)
          else:
              pass
  getFiles(cleaned_files)
  </code></pre>