It is possible to get the current date on a Windows system and the last modification date of a file, like thise:
date /T
echo %~tI%
(where %I
is the file within a FOR
loop)Both however depend on regional settings, so they need to be replaced by something else:
wmic os get localdatetime
Does somebody know how to fill in the question marks?
Background information, the idea is to get a result like the following:
Chop off the first eight characters (in order to get the day)
This makes it possible to see that the file has indeed been modified today.
I want to avoid regional settings in order to be sure of the amount of characters I need to chop off.
For timestamp comparisons, you could use forfiles
to find files modified today. This solution is more graceful than chopping substrings off of WMI query results I think.
@echo off & setlocal
set "file=notes.txt"
forfiles /d +0 /m "%file%" >NUL 2>NUL && (
echo %file% was modified today.
) || (
for %%I in ("%file%") do echo %%~I was last modified %%~tI
)
forfiles /?
in a cmd console for more info. The forfiles
command exits 0 on match, 1 on no match, allowing the use of conditional execution. Also, see this related question.