3

I am trying to delete files through

forfiles -p "E:\check" -s -m *.* -d -10 -c "cmd /c del /Q /S E:\check"

But if there is a file that is more than 10 days old, it removes all files in the folder.

Shubham Gupta
  • 33
  • 1
  • 3

1 Answers1

4

If there is a file that is more than 10 days old, it removes all files in the folder.

forfiles -p "E:\check" -s -m *.* -d -10 -c "cmd /c del /Q /S E:\check"

That is hardly surprising when you are deleting the directory you are searching (and all of its sub-directories) with the following command:

del /Q /S E:\check

Instead you need to delete the matching files. Try the following command:

forfiles -p "E:\check" -s -m *.* -d -10 -c "cmd /c del /q @path"

Further Reading

DavidPostill
  • 156,873