Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sun 25-Apr-2010 09:30:24

Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.

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

Incidentally, this task arose from my own 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.

  @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 +---------------------------------------------------+
  :: Set the appropriate variables

  set string_=%~1
  set source_=%~2
  set ignorecase_=%~3
  set help_=
  :: Syntax help, if necessary

  if not defined source_ set help_=true
  if defined ignorecase_ (
    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 %ignorecase_% "%string_%" "!file_!">nul
    if !errorlevel! NEQ 0 echo !file_!
  endlocal & goto :EOF

An example of usage:

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups Nov 6 2005, 9:09 am [M]