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
  • 3
  • 14
  • 20
Nick
  • 3
  • 1
  • 4
  • This is not working for me I tried this: `for %i in (C:\Test\*) do if not %i == a.c del %i` I entered this command in my batch file and ran it. – Nick May 05 '15 at 15:08

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
  • 12,837
  • 5
  • 37
  • 69