Search code examples
windowsbatch-filecmdforfiles

ForFiles command does not work with parameter /D +xx


This finds no files (two in the directory are only one day old):

for /d %%d in (%mydir%\*) do (
  cd %%d
forfiles /P %%d  /M *.ppt* /D +7 /C "cmd /c echo Converting @file"
)

When I change the /D parameter to /D -6 it's ok, also /D 25.10.2021 is ok.

But /D +7 never finds any file.

Is it a bug or feature?


Solution

  • Here's an example which is an adaption of what looks like the same method shown in aschipfl's answer within the link in their comment.

    @Set "MyDir=%UserProfile%\Videos"
    @For /F "Delims=" %%G In ('Dir "%MyDir%" /B /A:D 2^>NUL') Do @For /F "Delims=" %%H In ('^"Dir /B /A:-D 1^>NUL 2^>^&1 ^&^& %SystemRoot%\System32\forfiles.exe /P "%MyDir%\%%G" /D -0 /C "%SystemRoot%\System32\cmd.exe /D /C 0x22If @IsDir==FALSE %SystemRoot%\System32\forfiles.exe /M @File /D -8 1>NUL 2>&1 || Echo @Path0x22" 2^>NUL^"') Do @Echo Converting %%H
    @Pause
    

    I have left out any explanation, as the answer linked above, explains the methodology, this essentially wraps that methodology within a For /F loop.