I need to get the modification date of a file stored in a variable like this: YearMonthDayHourMinute
. So 01/21/2019 9:12 AM
would be 201901210912
. What I will be doing is comparing files to see which is newer, so it needs to be like this in 24 hour format. I was initially going to get it with this command: for %? IN ("%cd%\out.txt") do (echo %~t?)
and use the for loop to split the output apart, but I was wondering if the modification date from a for loop is locale dependent like %date%
? If it is, is there a way to check which type of format it is under, or is there a way to get a non-locale dependent modification date?
This is related to Why wont this function's variables set? Batch Code but I don't see how solving one would necessarily alter the other one, so I'm keeping them as separate questions.
Best Answer
There are two problems in the above code snippet:
name="!_ForString!"
: you need to escape the equals sign asname^="!_ForString!"
;wmic
output in aFOR /F
loop (explained below).:ParseWmicDatafile
subroutine in the following commented.bat
script should do the job:Here the
for
loops are%%A
to retrieve theLastModified
property name (%%A
) and value (%%B
);%%b
to remove the ending carriage return in the value returned;wmic
behaviour: each output line ends with0x0D0D0A
(<CR><CR><LF>
) instead of common0x0D0A
(<CR><LF>
).See Dave Benham's
WMIC
andFOR /F
: A fix for the trailing<CR>
problemOutput: