title: Batch Script to find a files inside all Sub Folders
body: <p>I have the multiple images in sub folder, I don't know how many folders are there. I want to Batch script to find listed names in all the folders and copy the images to destination folder. I tried below script but am getting file not found error. </p>
  
  <pre><code>@echo off
  
  rem Find files and copy files
  
  setlocal EnableExtensions EnableDelayedExpansion
  
  set "SourceBaseFolder=D:\System backup\picture batch file\Test\15oct2015"
  set "TargetBaseFolder=C:\OutputFolder"
  
  if not exist "%SourceBaseFolder%\*" (
      echo %~nx0: There is no folder %SourceBaseFolder%
      set "ErrorCount=1"
      goto HaltOnError
  )
  
  cd /D "%SourceBaseFolder%"
  
  if not exist "FileNames.txt" (
      echo %~nx0: There is no file %SourceBaseFolder%\FileNames.txt
      set "ErrorCount=1"
      goto HaltOnError
  )
  
  set "ErrorCount=0"
  for /F "usebackq delims=" %%N in ("FileNames.txt") do (
      for /R %%J in ("%%N*") do (
          set "FilePath=%%~dpJ"
          if "!FilePath:%TargetBaseFolder%=!" == "!FilePath!" (
              set "TargetPath=%TargetBaseFolder%\!FilePath:%SourceBaseFolder%\=!"
              md "!TargetPath!" 2&gt;nul
              if exist "!TargetPath!\*" (
                  echo Copying file %%~fJ
                  copy /Y "%%~fJ" "!TargetPath!" &gt;nul
              ) else (
                  set /A ErrorCount+=1
                  echo Failed to create directory !TargetPath!
              )
          )
      )
  )
  
  :HaltOnError
  if %ErrorCount% NEQ 0 (
      echo.
      pause
  )
  endlocal
  </code></pre>
  
  <p>Can any one fix this problem? Thanks in advance.</p>