title: Saving files based on filename to individual folders
body: <p>I have a list of 480 files and I would like to save them to 80 folders based on their filenames.  Examples of the filenames are:</p>
  
  <pre><code>LT50300281984137PAC00_sr_band1.tif
  LT50300281984137PAC00_sr_band2.tif
  LT50300282007136PAC01_sr_band1.tif
  LT50300282007136PAC01_sr_band2.tif
  LT50300282002138LGS01_sr_band1.tif
  LT50300282002138LGS01_sr_band2.tif
  </code></pre>
  
  <p>I want to save files that have matching characters in a slice of the first 21 characters [0:21] into folders that have that same name.  For example:</p>
  
  <pre><code>LT50300281984137PAC00_sr_band1.tif
  LT50300281984137PAC00_sr_band2.tif 
  </code></pre>
  
  <p>would go into folder titled <code>LT50300281984137PAC00</code></p>
  
  <p>and </p>
  
  <pre><code>LT50300282007136PAC01_sr_band1.tif
  LT50300282007136PAC01_sr_band2.tif
  </code></pre>
  
  <p>would go into folder titled <code>LT50300282007136PAC01</code></p>
  
  <p>I have already created the folders using this code:</p>
  
  <pre><code>import arcpy
  import os
  #pathway where there are only 80 .tif files, one for each landsat scene
  arcpy.env.workspace=r'F:\Sheyenne\Atmospherically Corrected Landsat\hank_masked\Band 1'
  #list of rasters in above pathway
  list1 = arcpy.ListRasters("*.tif")
  #output save pathway
  mainpath=r'F:\Sheyenne\Atmospherically Corrected Landsat\Individual Scenes\Main'
  
  #create folder for each landsatscene containing first 21 characters
  for raster in list1:
      rasterName=raster[0:21]
      if raster.startswith(rasterName.split("_")[0]):
          final_path=os.path.join(mainpath,rasterName)
          os.makedirs(final_path)
  </code></pre>
  
  <p>and now I want to take every file that has 'band' in the name like I showed above and store it in the correct folders but this is where I am stuck</p>