I doubt @Samos007 will come back to confirm, but I am assuming Samos actually used File Explorer to delete the files after updating their timestamps and sorting by date.
(And I’m happy that Samos didn’t just expect us to solve the problem, but put more effort into it; that’s encouraging that there are still random users who do put in effort into their own issues.)
If Samos does return, Scott’s “without any special tools” challenged me: using only Windows builtin commands, two one-liner alternatives:
for %F IN ( *.txt ) DO @( FIND /C "special text" %F > NUL && DEL %F) for %F IN ( *.txt ) DO @( FINDSTR /L "special text" %F > NUL && DEL %F)the builtin FIND command, using FIND /C, will print out a count of the number of matches, and also return an %ErrorLevel% of 0 to the system if it matches, or 1 if there’s no match; since I don’t care about the printing, I redirect it to NUL. I then use the windows && to cause the next command to only run if the previous %ErrorLevel% was 0 (a match). DEL will thus be run only on any files that match
The builtin FINDSTR command, using FINDSTR /L, works similarly.
Someday, I’ll maybe think “FINDSTR” or “FIND” instead of gnuwin32’s “grep” for matching text in Windows files… but probably not before MS has discontinued cmd.exe completely and forced me to learn PowerShell.