title: Powershell: Move files to folder based on Date Created
body: <p>I'm not a coder but I've still attempted tweaking PS scripts found here and still can't get the behavior I desire. The tough part for me has been the 2 digit Day requirement (dd). After several noob attempts I would like some help.</p>
  
  <p>I have a folder that contains hundreds of JPG's. I manually sort these JPG's into folders based on the date taken. Folder name examples are 2015.02.04, 2016.10.31, 2016.12.01.</p>
  
  <p>1) I would like a script to scan my JPG folder.
  2) For each file, scan the date
  3) If the file was created June 1st, 2016 then it will be moved to .\2016.06.01</p>
  
  <p>Help a brother out?</p>
  
  <pre><code>$Filepath = ""
  $file = ""
  $date  = ""
  $month   = ""
  $year    = ""
  $MonthPath   = ""
  
  $FilePath = Read-Host "Place the directory which contains the files."
  
  Write-Warning "Note: This action can take several minutes, depending on the amount of files in $FilePath."
  
  get-childitem $FilePath | % {
  
    $file = $_.FullName 
      $date = Get-Date ($_.LastWriteTime)
  
    $month = $date.month
    $year = $date.year
    $day = $date.day
      $MonthPath = "$FilePath\$year.$month.$day"
      Write-Verbose "month = $month"
      Write-Verbose "Date = $date"
      Write-Verbose "year = $year"
      Write-Verbose "FilePath = $FilePath" 
      Write-Verbose "Filename = $file"
      Write-Verbose "MonthPath = $MonthPath"
  
      if(!(Test-Path -Path "$MonthPath" )){
          Write-Verbose "Creating log location $MonthPath."
          #Write-Host -backgroundcolor green -ForegroundColor black "Creating log location $MonthPath."
          Write-Verbose "MonthPath inside path test = $MonthPath"
          New-Item -ItemType directory -Path $MonthPath | Out-null
      }
      ELSE {
          #Write-Host -backgroundcolor green -ForegroundColor black "Log location exists already exist $MonthPath"
          Write-Verbose "Log location exists already exist $MonthPath" 
          }
      move-item "$file" "$MonthPath" | Out-null
  }
  
  Write-Warning "All files are sorted now based upon year and month."
  </code></pre>