title: Randomize filenames but keep extensions
body: <p>I am trying to randomize filenames in a directory. The problem is that the extension disappears after renaming. What do I need to change in order to new filenames have their original extensions?</p>
  
  <pre><code>from string import ascii_lowercase
  from random import choice, randint, random
  import os
  
  def randomize_files(dir):
      for f in os.listdir(dir):
          path = os.path.join(dir, f)
          if os.path.isfile(path):
              newpath = os.path.join(dir, ''.join([choice(ascii_lowercase) for _ in range(randint(5, 8))]))
              os.rename(path, newpath)
  
  randomize_files("/tmp/tset21")
  </code></pre>