Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I find files which do NOT contain the search string?

1,052 views
Skip to first unread message

Timo Salmi

unread,
Nov 5, 2005, 11:35:15 PM11/5/05
to
DRAFT:

124) How do I find files which do NOT contain the search string?

@echo off & setlocal enableextensions enabledelayedexpansion
echo +---------------------------------------------------+
echo ^| NOFIND.CMD Find files not containing a string ^|
echo ^| By Prof. Timo Salmi, Last modified Sun 6-Nov-2005 ^|
echo +---------------------------------------------------+
echo.
::
:: Set the approbiate variable
set string_=%~1
set source_=%~2
set ignore_=%~3
set help_=
::
:: Syntax help, if necessary
if not defined source_ set help_=true
if defined ignore_ (
if /i not "%~3"=="/i" set help_=true
)
if defined help_ (
echo Usage: %~0 "string" "[[drive:][path]filename[ ...]]" [/i]
echo Wildcards allowed
echo Search also subfolders implicitly assumed
goto :EOF)
::
:: Do the nofind recursively
for /f %%f in ('dir /b /s "%source_%"') do (
set file_=%%~dpnxf
find %ignore_% "%string_%" "!file_!">nul
if !errorlevel! NEQ 0 echo !file_!
)
endlocal & goto :EOF

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

billious

unread,
Nov 6, 2005, 1:09:15 AM11/6/05
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:436d8810$0$31867$9b53...@news.fv.fi...

[1]@echo off
[2]if "%~3"=="" goto p3ok
[3]if /i "%~3"=="/I" goto p3ok
[4]:: param3 error - help
[5]:syntax
[6]echo Usage: %~0 "string" "[[drive:][path]filename]" [/i]
[7]echo wildcards allowed
[8]goto :eof
[9]:p3ok
[10]if "%~2"=="" goto syntax
[11]if exist "%~2" for /f "delims=" %%i in ('dir /b/s/a:-d "%~2" ') do find
%~3 "%~1" "%%i">nul&if errorlevel 1 echo %%i

HTH

...Bill


Timo Salmi

unread,
Nov 6, 2005, 4:12:47 AM11/6/05
to
billious wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote
>> DRAFT:
(snip)

> [11]if exist "%~2" for /f "delims=" %%i in ('dir /b/s/a:-d "%~2"') do find %~3 "%~1" "%%i">nul&if errorlevel 1 echo %%i

Neat. That's exactly why it is useful first to post the drafts. A
Google reference included to the said posting.

Incidentally, this task arose from a real need to check through a
number of html files which I had to edit. I wanted to see if I missed
making one of the intended adjustments.

Dr John Stockton

unread,
Nov 7, 2005, 8:21:31 AM11/7/05
to
JRS: In article <436d8810$0$31867$9b53...@news.fv.fi>, dated Sun, 6
Nov 2005 06:35:15, seen in news:alt.msdos.batch.nt, Timo Salmi
<t...@uwasa.fi> posted :

>
>124) How do I find files which do NOT contain the search string?

or as mtr -o/~ *.txt - the

There, mtr is MiniTrue, for UNIX, Win-32; the string or strings can be
RegExps, etc. As in sig, or in ftp://garbo.uwasa.fi/pc/fileutil/ &
mirrors. SFN only.

I use MiniTrue very frequently in editing my Web site master - for
reading, searching, or altering.

One useful feature is that mtr [a-ik-z]*.htm javascript can be used
to find occurrences of 'javascript' in *.htm files whose names begin
with a letter other than j. Or, of course, non-occurrences.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/>

0 new messages