title: How to rename multiple files in efficient way?
body: <p>I have created a program to rename multiple files in a directory. My goal was to serialize them and pad with 0 depending on amount of files in directory (example: for 11 jpg files last one would be 011.jpg). I want make it work efficient with large amounts of files on multiple platforms. Here is my code:</p>
  
  <pre><code>from pathlib import Path
  
  number = 1
  amount = 0
  files = []
  
  directory = Path.home() / 'Photos'
  
  for file in directory.iterdir():
      if file.is_file():
          files.append(file)
          amount+=1
  
  for file in files:
      file.replace(f'{directory}/{number:0{len(str(amount))+1}}{file.suffix}')
      number += 1
  </code></pre>
  
  <p>1) Is there way to avoid two loops? First for getting amount of elements - for padding purpose. Then second for renaming. If not is there something that I can improve to make it work better?</p>
  
  <p>2) Is it universal way to get to users photos directory? Not depending on platform or system language?</p>