I wanted a one liner to delete all files older than 14 days in certain folder.
This is my command
forfiles -px:\logs -s -m*.log -d-14 -c"CMD /C del @file"
but when executed it outputs "can't execute (error 2)" for every file it finds. If the -c "CMD /c del @file " is omitted it works fine producing a list of files older than 14 days. I first thought it might be a permission issue; but any action on the file produces the same result and I am admin on the comptuer.
It is however a network share if that makes a diffrence.
Thanks
What is the value of @file, and what is the current directory when you're running the code?
winerror.h says that error 2 is
#define ERROR_FILE_NOT_FOUND 2L
so I would try fully qualifying your path to the file that is getting deleted.
--EDIT:
which you can do by doing
forfiles -px:\logs -s -m*.log -d-14 -c"CMD /C del @path"
instead of
forfiles -px:\logs -s -m*.log -d-14 -c"CMD /C del @file"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With