I was looking at putting a script together that periodically deletes files from a directory which are older than a given time, e.g. 10 days. I found the forfile command on the Microsoft TechNet site, which looked like it would do the trick. The page has several examples for passing a date parameter, but every example came back with various errors.
The example to list all files older than 100 days on drive C: is:
forfiles /p c:\ /s /m *.* /d t-100 /c "cmd /c echo @file : date >= 100 days"
This causes the error “ERROR: Invalid date specified. Type “FORFILES /?” for usage.”
It’s a simple fix though, the “t” in the date parameter is causing the issue. There’s no need for a “t” to be in there. Simply remove it and it works fine.
forfiles /p c:\ /s /m *.* /d -100 /c "cmd /c echo @file : date >= 100 days"
Other issues I encountered with the examples were due to there being no space between a parameter and value. For instance if you had /m*.* (no space between param and value) you will get the error message “ERROR: Invalid argument/option – ‘/m*.*’.”. To fix it, just add a space: /m *.*