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
[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
> [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.
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/>