A batch file that removes a file that was not last modified today
5 answers
Unfortunately, you cannot do this in a reliable and general way (*).
Powershell, Cygwin, Unix Tools are great solutions if you can be sure they will be installed on the target machine.
I wrote a small utility that takes a wildcard path with a number of days and deletes all files matching a path that is greater than the specified number of days. In my environment, this was more convenient than installing a third party package.
(*) The following will work for your specific case (modification date is not today) as long as the short date format in your locale includes a century (i.e. 10 characters). But it doesn't generalize to N days, and I don't like relying on the computer's regional settings for this kind of thing:
for %%i in (log.txt) do SET FILETIME=%%~ti
IF NOT "%FILETIME:~0,10%" == "%DATE%" DEL /f log.txt
+1
a source to share