title: Moving files by starting letter in powershell, python or other scripting language running windows
body: <p>I need a script than can recursively traverse c:\somedir\ and move files to c:\someotherdir\x\ - where x is the starting letter of the file.</p>
  
  <p>Can anyone help? </p>
  
  <hr>
  
  <p>Ended up with this one:</p>
  
  <pre><code>import os
  from shutil import copy2
  import uuid
  import random
  
  SOURCE = ".\\pictures\\"
  DEST = ".\\pictures_ordered\\"
  
  for path, dirs, files in os.walk(SOURCE):
      for f in files:
          print(f)
          starting_letter = f[0].upper()
          source_path = os.path.join(path, f)
          dest_path = os.path.join(DEST, starting_letter)
  
          if not os.path.isdir(dest_path):
              os.makedirs(dest_path)
  
          dest_fullfile = os.path.join(dest_path, f)
  
          if os.path.exists(dest_fullfile):            
              periodIndex = source_path.rfind(".")
              renamed_soruce_path = source_path[:periodIndex] + "_" + str(random.randint(100000, 999999))  + source_path[periodIndex:]
              os.rename(source_path, renamed_soruce_path)
              copy2(renamed_soruce_path, dest_path)            
              os.remove(renamed_soruce_path)
          else:
              copy2(source_path, dest_path)
              os.remove(source_path)`
  </code></pre>