I am trying to create a list of file names whereby the LastModified
timestamp is greater than a set value.
I think, I am very close with the following:
@echo off
setlocal DisableDelayedExpansion
REM delete existing output file
for %%f in (_modified) do if exist %%f.txt del %%f.txt
REM hard code timstamp threshold
set lastTime=20140801000000
echo "lastTime=%lastTime%"
REM set folder to CWD
set "folder=%CD:~2%"
echo "folder=%folder%"
REM search files in folder with extension 'jpg'
FOR /F "skip=1 tokens=1*" %%a in (
'"wmic datafile where (path='%folder:\=\\%\\' AND Extension='jpg') get 'File Name',LastModified"'
) do (
FOR /F "delims=." %%B in ("%%b") do (
if %%B LEQ %lastTime% (echo "%%B LEQ1") else (echo "%%B GEQ1")
if %%B GEQ %lastTime% (echo "%%B GEQ2") else (echo "%%B LEQ2")
if %%B GEQ %lastTime% (
echo %%B %%a>> _modified.txt))
)
However, for a folder which contains 2 jpg files, one of which has a last modified of 2010-02-22 and the other 2014-08-14 the script prints:
"lastTime=20140801000000"
"folder=\test"
"20100222210624 LEQ1"
"20100222210624 GEQ2"
"20140814155354 LEQ1"
"20140814155354 GEQ2"
And the output file contains both file names instead of the expected result of just one.
Obviously the LEQ/GEQ comparison is not working as I expect, but I'm not sure what is incorrect.