Frage

I've got this piece of batch code:

for /D %%f in (E:\images\*) do E:\jpegoptim.exe -v --strip-all "%%f\*.jpg"

I need to add a condition inside the 'do' statement, to run the executable only on the files whose creation date is greater than '2014-01-01'.

I know DIR /T lists files with creation dates, but how can I integrate it in my code? Is there a way to simply get the date of %%f ?

War es hilfreich?

Lösung

Using the modifier %%~tx in the FOR loop. You can do like this :

@echo off

set $Lim=20140101

setlocal Enabledelayedexpansion

for /f "delims=" %%a in ('dir /s /b/a-d "E:\images\*.txt"') do (
 set $FileDate=%%~ta
 set $FileDate=!$FileDate:~6,4!!$FileDate:~3,2!!$FileDate:~0,2!
 if !$FileDate! Gtr %$Lim% echo E:\jpegoptim.exe -v --strip-all "%%~fa"
)

Test it and remove the echo if the output is correct for you

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top