title: Batch file to move files to folders named with year and month from modification date
body: <p>I have thousands of files that need to be moved into folders named by the year and month in the modification date.  I've done this before with success, but for some reason it's failing as the main string value is not getting set.  Here's what I have:</p>
  
  <p>A test folder with 3 files.  All files have VERY long names. such as:
  LocalId=99a73-f852d-407907-98ce-4ab02dde5b41_SessionId=999999.flv</p>
  
  <p>The above file name is representative of the files I am working with.</p>
  
  <p>They exist in a folder: E:\backups\test</p>
  
  <p>They are the ONLY items in this folder.</p>
  
  <p>When I run the test command: for /f %a in ("E:\backups\test*.*") do set filedate=%~ta</p>
  
  <p>The proper information is returned: set filedate=12/29/2014 12:44 PM</p>
  
  <p>My batch file looks like this:</p>
  
  <pre><code>@rem ############################################################
  @rem SETTING TIME AND DATE PARAMETERS FOR CREATION OF LOG FILES
  set hr=%time:~0,2%
  if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
  set outFile=%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%
  @rem ############################################################
  @rem ############################################################
  @rem SETTING PATHS FOR PROCESSING LOG FILES
  SETLOCAL ENABLEDELAYEDEXPANSION
  SET dir=E:\backups\test
  SET logDir=C:\scripts\logs
  SET datesort=%logDir%\logfile.name.%outFile%.log
  @rem ############################################################
  @rem PARSING FILE MODIFIED DATE FOR YEAR AND MONTH
  @rem CALLS PROCESS TO SET YEAR AND MONTH
  @rem MOVES FILES INTO DATED FOLDERS
  @rem ROBOCOPY TAKES CARE OF FOLDER CREATION AUTOMATICALLY
  @rem SETS YEAR AND MONTH
  FOR /f %%a IN ('dir /b /a-d "%dir%\*.flv" ') DO (
   SET "filedate=%%~ta"
    CALL :finddate
    robocopy "%dir%" /XX /r:10 %dir%\!year!!month!\ "!filedate!" /MOV &gt;&gt; %datesort%
  )
  GOTO sendmail
  :finddate
  SET year=%filedate:~6,4%
  SET month=%filedate:~0,2%
  GOTO :EOF
  GOTO finddate
  :sendmail
  @rem ############################################################
  @rem SENDING MAIL NOTIFICATION WITH LOG
  &lt;command for sending email notification&gt;
  </code></pre>
  
  <p>What am I missing here to make this work?  I'm sure it's something simple.  Maybe I'm just too tired to pick up on it.  </p>