title: How do you move files, but not folders, within a directory?
body: <p>I created a simple Python script to move files from a folder/directory to a newly created folder within the same path.  The idea is to move files that were modified more than five days ago.  I'm having issues where it is moving everything in the base path, including other subfolders.  Is there a way to just move files, and not folders?</p>
  
  <p>I tried the <code>.endswith</code> function from the <code>os.path</code> module, but no luck.  I believe I am missing something revolving around a wildcard.</p>
  
  <p>This is my code:</p>
  
  <pre><code>if not os.path.exists(new_path):
      os.mkdir(new_path)
      print('Successfully created the directory %s' % new_path)
  else:        
      print('The directory %s already exists' % new_path)
  
  for f in os.listdir(dir_path):
      path_and_file = os.path.join(dir_path,f)
      if int((datetime.datetime.fromtimestamp(os.path.getmtime(f)).strftime("%Y-%m-%d")).replace("-","")) &lt; int(threshold_date.replace("-","")):
          destpath_and_file = os.path.join(new_path, f)
          shutil.move(path_and_file,destpath_and_file)
  </code></pre>
  
  <p>The code works, moving everything within the base folder.  However, it is moving subfolders too.  I would like to move files only. (For example, only move .xls/.xlsx files.)</p>
  
  <p>Thank you very much.</p>