0

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?

Compo
  • 36,585
  • 5
  • 27
  • 39
Marco
  • 35
  • 1
  • 3
  • 1
    Do you really have files that you created next week? – Stephan Oct 31 '21 at 12:41
  • ah thats my problem.. i thought it show all new files from the last 7 days. you are right. i read the docs 3 times .. my fault... sorry. – Marco Oct 31 '21 at 13:12
  • is there any way to show all files newer then 7 days ? – Marco Oct 31 '21 at 13:13
  • `forfiles`' `/D` option is useless with `+` and a number of days, because it looks for items modified in the future, which is of course useless without a time machine. But there is a work-around – take a look a this: [FORFILES date -after- (date calc in cmd file)](https://stackoverflow.com/q/19296588) – aschipfl Oct 31 '21 at 18:08

1 Answers1

0

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.

Compo
  • 36,585
  • 5
  • 27
  • 39