0

My current code to delete all files in a folder older then 2 days is :

forfiles /p "C:\Test" /s /m *.* /c "cmd /c Del /F /Q @path" /d 2

There is one .idf file among all other files. I want to delete all files except the one .idf file. What do I change to get the current code to ignore the file? If it is not possible, any new command will be helpful.

Cfinley
  • 1,435
Nick
  • 3

1 Answers1

0

To improve your approach a little:

  • keep forfiles with /d -2 switch to treat older files only
  • use for %G with if /I [%~xG] neq [.idf] to omit files with .idf extension
  • double all % if run from a batch file: %%G instead of %G etc.
  • remove @echo no sooner than debugged.

The command:

forfiles /p "C:\Test" /s /m *.* /c "cmd /c for %G in (@path) do @if /I [%~xG] neq [.idf] @echo del /F /Q %G" /d -2

Resources (required reading):

JosefZ
  • 13,855