title: FINDSTR: help understanding results. Returns nothing, but no error when there is one expected?
body: <p>I am writing a batch file. part of the program will compare the list of files in a 'source' folder. With the contents of a list in a text file. </p>
  
  <p>I loop through each file in the folder, and search for its filename in the text file using FINDSTR</p>
  
  <p>Everything works until there is a filename in the source folder that doesnt exist in the text file. </p>
  
  <p>the findstr code:</p>
  
  <pre><code>for /f %%o in ('findstr %name% old.txt') do (
      echo o=%%o &gt;&gt; result.txt
      if %%o==%name% (
          echo %name% exists
      ) ELSE (
          echo %name% does not exists
      )
  )
  </code></pre>
  
  <p>Again, the problem occurs when FINDSTR searches for a filename that is not in the text file. </p>
  
  <p>when it reaches that point it outputs the variable %%o as being '%o' and echos nothing. So it sends nothing to the results.txt.</p>
  
  <p>This doesnt trigger an ERRORLEVEL change but also will not echo anything. I have tried outputing the errorlevels but they are also empty. I just dont understand what FINDSTR is doing in this instance. </p>
  
  <p>the FULL batch file: (its my first one. forgive any mistakes) </p>
  
  <pre><code>  ::return the raw (/b) list of files 
    FORFILES /p %~dp0source\ /s /m "*.cr2" /C "cmd /c echo @path" &gt; new.txt
  
    ::pull file path for each file and send to subroutine
    for /f %%n in ('FORFILES /p %~dp0source\ /s /m "*.cr2" /C "cmd /c echo @path"') do (
  
      call :dequote %%n
  
    )
  
  ::subroutine for removing quotes 
  ::and returning the filename, extension, and path
  :dequote
  set fullPath=%~f1
  set fileName=%~n1
  set fileExt=%~x1
  set filePath=%~dp1
  set name=%fileName%&amp; set npath=%filePath%&amp; set ext=%fileExt%&amp; set fpath=%fullPath%
  echo %fpath%
  echo %npath%
  echo %name%
  echo %ext%
  
  for /f %%o in ('findstr %name% old.txt') do (
      echo o=%%o &gt;&gt; result.txt
      if %%o==%name% (
          echo %name% exists
      ) ELSE (
      echo %name% does not exists
      )
  )
  </code></pre>
  
  <p>This only happens on the last filename sent to findstr. Any suggestions or direction would be very appreciated. Ive tried and read everything I can get my hands on. </p>
  
  <p>Thank You for your time. </p>
  
  <hr>
  
  <p>UPDATE: 9-9-15</p>
  
  <p>Here is the working final batch file i created using the help on this page. It creates a hotfolder that will edit any new files added to it until you stop the script from running: </p>
  
  <pre><code>  :start
  
    :: return the raw (/b) list of files and full path to source text
    FORFILES /p %~dp0source\ /s /m "*.cr2" /C "cmd /c echo @path" &gt; source.txt
    IF %ERRORLEVEL% EQU 1 goto :start
  
    ::join new and old data, return only what is shared in common (/g)
    findstr /I /L /G:"source.txt" "output.txt" &gt; found.txt
    IF %ERRORLEVEL% EQU 1 copy /y source.txt notFound.txt
  
    ::join found file names and source filenames, return those that do not have a match
    findstr /I /L /V /G:"found.txt" "source.txt" &gt;&gt; notFound.txt
    IF %ERRORLEVEL% EQU 2 echo error no match
  
    ::for each line of notFound.txt, dequote and break apart
    for /f %%n in (notFound.txt) do (
      echo n=%%n
      call :dequote %%n
    )
  
    :dequote
    set fullPath=%~f1
    set fileName=%~n1
    set fileExt=%~x1
    set filePath=%~dp1
    set name=%fileName%&amp; set npath=%filePath%&amp; set ext=%fileExt%&amp; set fpath=%fullPath%
    echo %fpath%
    echo %npath%
    echo %name%
    echo %ext%
  
    cd %nPath%
    if NOT [%1]==[] (
      echo converted %name%
      convert -negate -density 600 -colorspace gray flatField.cr2 %name%%ext% -compose Divide -composite %name%.tif
      move %name%.tif %~dp0output
      cd %~dp0
      del notFound.txt
      copy /y source.txt output.txt
      ) ELSE (
       echo end of batch else
       cd %~dp0
    )
  </code></pre>