1

Tell me how you can find out the date the file was created in BAT. We have a variable for %%~ti, but it only indicates the file's modification date. And how do you know it is the date the file was created?

3
  • Doing date time handling in .bat files is quite hard. Isn't it possible for you to switch to powershell? There it is much easier, as you can see here.
    – Oliver
    Commented Sep 22, 2015 at 6:29
  • There is an option: FOR /f %%i IN ('DIR "%~1" /t:c ^| FINDSTR /E "%%~nf%%~xf"') DO ECHO %%i >> "%~2" It is necessary to remove the recurrence Commented Sep 22, 2015 at 6:45
  • you surely mean FINDSTR /E "%~1"?
    – Stephan
    Commented Sep 22, 2015 at 6:50

2 Answers 2

1
@echo off
for /f "skip=5 tokens=1,2 delims= " %%a in ('dir /a-d /tc "%~1"') do (
  echo Date: %%a, Time: %%b, File: %~1
  exit /b 0
)
0

At least these three options exist, which are all scriptable.

There can be limitations depending on the OS version, and the language, and characters being used.

  • Powershell
  • WMIC
  • VBS script using WSH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.