Windows batch file - sorting files by modified and/or creation date into folders
<p>I'm trying to adapt existing batch files posted on StackOverflow for my task but need guidance on a particular area of Batch File syntax and commands. </p>

<p>The task is to sort a folder full of image files into sub-folders by creation and/or modification date (whichever is the earlier).</p>

<p>The below script works for the file creation date, however, where a group of files have been copied in from another folder then they all have the same creation date (but retain the earlier 'modified' date, hence why I wish to use whichever date is the earliest)</p>

<p>Any suggestions gratefully received.</p>

<p>The code I've been looking at adapting:</p>

<pre><code>    @echo off
    setlocal enabledelayedexpansion
    set RawData="C:\Users\Jernau\source_image\*.jpg"
    set ArchiveFolder="C:\Users\Jernau\source_image\organised\"
    for %%a in ("%RawData%") do (
        echo Processing %%~nxa ...
        set File=%%~fa
        for /f "tokens=1* delims=," %%a in ('wmic datafile where "name=
            '!File:\=\\!'" get 'CreationDate' /format:csv ^| find /i  
            "%ComputerName%"') do (set CreationDate=%%b)
        echo %%~nxa: !CreationDate!
        set cYear=!CreationDate:~0,4!
        set cMonth=!CreationDate:~4,2!
        set cDay=!CreationDate:~6,2!
        set TimeStamp=!cYear!-!cMonth!-!cDay!
        if not exist "%ArchiveFolder%\!TimeStamp!" (
            md "%ArchiveFolder%\!TimeStamp!"
        )
        move "!File!" "%ArchiveFolder%\!TimeStamp!"
    )
</code></pre>