Reputation: 201
I'm printing findstr results as a text file and deleting the files which are printed as a text file, but i am facing some issues !
My code is like:
@echo off
findstr /s /m "Trojan" "C:\*.*">>"C:\result.txt" 2>nul
for %%i in (C:\result.txt) do del %%i
But, i am not able to delete the file(s) with the help of the code above, because it's not delteing file(s) which have spaces in their path
Example-
It is deleting "C:\Anything.exe" which has "Trojan" as a string
It is not deleting "C:\Anything xyz.exe" which has "Trojan" as a string
Please Help to optimize my code !!!
Upvotes: 1
Views: 44
Reputation: 70951
for /f "delims=" %%i in (C:\result.txt) do del "%%i"
You need for /f
to read the file, an empty delimiter list to avoid splitting the line on spaces while reading the file and proper quoting in the del
command.
Upvotes: 2