title: How to move files in a pythonic way?
body: <p>First, sorry for the long post.</p>
  
  <p>I need to move .xlsx files from the previous days from one folder to another, but i shoudnt move the files with today date, just the files from previous days.</p>
  
  <p>In my current code, i am moving the files by specifying each one of them with a Minus X days, but i think the code is not in the best 'shape' nor the best performance/quality</p>
  
  <pre><code>import datetime,os, glob, shutil
  from pathlib import Path
  
  dir_carteiras = r"C:\Users\User\Documents\Carteiras"
  test = os.listdir(dir_carteiras)
  
  for item in test:
      if item.endswith(".jpg"):
          os.remove( os.path.join(dir_carteiras, item))
  
  #get todays  date and a calculation for today -1 day
  today=datetime.date.today()
  minus_one_day=datetime.timedelta(days=-1)
  
  #use the calculation to get previous 5 days strings
  d_N1=today+minus_one_day
  d_N1_ = d_N1.strftime('%Y.%m.%d')
  d_N2=d_N1+minus_one_day
  d_N3=d_N2+minus_one_day
  d_N4=d_N3+minus_one_day
  d_N5=d_N4+minus_one_day
  
  #format dates for the files formats
  Date_Carteira_N1 = d_N1.strftime('%d_%m_%Y')
  Date_Carteira__0 = today.strftime('%d_%m_%Y')
  Date_Carteira_N2 =d_N2.strftime('%d_%m_%Y')
  Date_Carteira_N3 =d_N3.strftime('%d_%m_%Y')
  Date_Carteira_N4 =d_N4.strftime('%d_%m_%Y')
  Date_Carteira_N5 =d_N5.strftime('%d_%m_%Y')
  Alocacao_0 = today.strftime('%Y%m%d')
  Alocacao_N1 = d_N1.strftime('%Y%m%d')
  Alocacao_N2 = d_N2.strftime('%Y%m%d')
  Alocacao_N3 = d_N3.strftime('%Y%m%d')
  Alocacao_N4 = d_N4.strftime('%Y%m%d')
  Alocacao_N5 = d_N5.strftime('%Y%m%d')
  
  #folder destination
  NewFolderPath = dir_carteiras+"\Historico"
  Path(NewFolderPath).mkdir(parents=True, exist_ok=True)
  
  #Move the "Carteira" files from previous 5 days
  Carteiras_move_N1 = glob.glob(r'C:\Users\\Documents\Carteiras\*'+Date_Carteira_N1+'.xlsx', recursive=True)
  for f in Carteiras_move_N1:
          shutil.move(f,NewFolderPath)
  Carteiras_move_N2 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Date_Carteira_N2+'.xlsx', recursive=True)
  for f in Carteiras_move_N2:
          shutil.move(f,NewFolderPath)
  Carteiras_move_N3 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Date_Carteira_N3+'.xlsx', recursive=True)
  for f in Carteiras_move_N3:
          shutil.move(f,NewFolderPath)
  Carteiras_move_N4 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Date_Carteira_N4+'.xlsx', recursive=True)
  for f in Carteiras_move_N4:
          shutil.move(f,NewFolderPath)
  Carteiras_move_N5 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Date_Carteira_N5+'.xlsx', recursive=True)
  for f in Carteiras_move_N5:
          shutil.move(f,NewFolderPath)
  
  #Move the "Alocacao" files from the previous 5 days
  Alocacao_move_N1 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Alocacao_N1+'.xlsx', recursive=True)
  for f in Alocacao_move_N1:
          shutil.move(f,NewFolderPath)
  Alocacao_move_N2 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Alocacao_N2+'.xlsx', recursive=True)
  for f in Alocacao_move_N2:
          shutil.move(f,NewFolderPath)
  Alocacao_move_N3 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Alocacao_N3+'.xlsx', recursive=True)
  for f in Alocacao_move_N3:
          shutil.move(f,NewFolderPath)
  Alocacao_move_N4 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Alocacao_N4+'.xlsx', recursive=True)
  for f in Alocacao_move_N4:
          shutil.move(f,NewFolderPath)
  Alocacao_move_N5 = glob.glob(r'C:\Users\User\Documents\Carteiras\*'+Alocacao_N5+'.xlsx', recursive=True)
  for f in Alocacao_move_N5:
          shutil.move(f,NewFolderPath)
  </code></pre>
  
  <p>EDIT with Tylerr's answer try:</p>
  
  <pre><code>import os
  import shutil
  from datetime import datetime
  
  dir_carteiras = r"C:\Users\GuilhermeMachado\Documents\Carteiras"
  test = os.listdir(dir_carteiras)
  NewFolderPath = dir_carteiras+"\Historico"
  
  datetime_object = datetime.now()
  today = datetime_object.day
  month = datetime_object.month
  year = datetime_object.year
  
  for file in list(filter(os.path.isfile, os.listdir(dir_carteiras))):
      unix_time = os.path.getmtime(file)
      date = datetime.utcfromtimestamp(unix_time)
      date_day = int(date.strftime("%d"))
      date_month = int(date.strftime("%m"))
      date_year = int(date.strftime("%Y"))
      if date_day &lt; today or date_month &lt; month or date_year &lt; year:
          shutil.move(file, NewFolderPath)
  </code></pre>