Findstr help
Moderator: DosItHelp
Findstr help
Hey guys i need some help i want to do a file that searchs multiple things in multiple files, say what files has that strings and then delete the files that has that string.
Regrats rfpd
Regrats rfpd
Re: Findstr help
The following code displays .txt files of the current directory which contain 111 AND 222 AND 333.
Regards
aGerman
Code: Select all
@echo off
for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
for /f "delims=" %%b in ('
findstr /c:"111" "%%a" ^>nul ^&^&
findstr /c:"222" "%%a" ^>nul ^&^&
findstr /mc:"333" "%%a"
') do (
echo "%%b"
)
)
pause
Regards
aGerman
Re: Findstr help
it's not showing the name of the files that has the string
Re: Findstr help
Hmm, works for me. Please give an example for testing.
Regards
aGerman
Regards
aGerman
Re: Findstr help
it's working sorry my mistake but it's not deleting the files i'm tring but i can't this is what i have:
Code: Select all
@echo off
for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
for /f "delims=" %%b in ('
findstr /c:"hey" "%%a" ^>nul ^&^&
findstr /c:"gh" "%%a" ^>nul ^&^&
findstr /mc:"delete" "%%a"
') do (
echo %%b
del %%b
)
)
pause
Re: Findstr help
But the ECHO command shows the right files?
In this case it could be that you've got file names with spaces. Try to enclose the variable in double quotes.
In this case it could be that you've got file names with spaces. Try to enclose the variable in double quotes.
Code: Select all
@echo off
for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
for /f "delims=" %%b in ('
findstr /c:"hey" "%%a" ^>nul ^&^&
findstr /c:"gh" "%%a" ^>nul ^&^&
findstr /mc:"delete" "%%a"
') do (
echo %%b
del "%%b"
)
)
pause
Re: Findstr help
i run it as administrator and it says file not founded
Re: Findstr help
I see. If you run it as administrator the working directory is %SystemRoot%\system32.
If you want to run it in the batch directory you could try this:
Regards
aGerman
If you want to run it in the batch directory you could try this:
Code: Select all
@echo off
pushd "%~dp0"
for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
for /f "delims=" %%b in ('
findstr /c:"hey" "%%a" ^>nul ^&^&
findstr /c:"gh" "%%a" ^>nul ^&^&
findstr /mc:"delete" "%%a"
') do (
echo %%b
del "%%b"
)
)
popd
pause
Regards
aGerman
Re: Findstr help
stil not working but thanks anyways