title: In Windows shell, How do I echo the date of the oldest file in a directory?
body: <p>I have the following code (which works well) in a batch file for listing directories recursively with a filecount for each directory, but besides what I already have, I need to know the date of the oldest file in current directory, where it says <code>I_NEED_YEAR_HERE</code>, how can I do that?</p>
  
  <pre>
  @echo off
  
  setlocal disableDelayedExpansion
  if "%~1"=="" (call :recurse ".") else call :recurse %1
  exit /b
  
  :recurse
  setlocal
  set fileCnt=0
  for /d %%D in ("%~1\*") do call :recurse "%%~fD"
  for /f %%F in ('dir /b /a-d "%~1\*" 2^>nul ^| find /v /c ""') do (
    set /a fileCnt+=%%F 
  )
  echo %~f1 has %fileCnt% files and the oldest file is from year I_NEED_YEAR_HERE
  ( 
    endlocal
    set /a fileCnt+=%fileCnt%
  )
  
  exit /b
  </pre>