title: Batch file to move files by date modified
body: <p>I have written a batch file, which creates empty folders for each date. My next task is to create another batch file, which moves each file in a directory, into the relevant date folder, based on their date modified. I have read numerous forums and articles on how I can achieve this, but with my limited batch file knowledge, I just cannot seem to get it to work. The code I currently have is shown below, though this does not seem to pull in the date modified. Any help is much appreciated!</p>
  
  <pre><code>SET directory="\directory\path\archive"
  
  FOR /f %%a in ('dir /b "%directory%"') do (
  
  SET fdate=%%~Ta
  
  MOVE "%directory%\%%a" "%directory%\%fdate%"
  </code></pre>