title: Combining CSV files without any headers using batch
body: <p>I wish to combine all CSV/TXT files within a directory using a batch script and was hoping you guys could help - pretty new to scripting so please forgive me if I ask for an explanation of what each line does,
  I did find something useful however but when tested it still keeps one header row. I hoped it would merge all files - no headers. </p>
  
  <p>for reference:</p>
  
  <pre><code>@echo off
  setlocal enableextensions disabledelayedexpansion
  
  rem configure paths
  set "source=C:\Users\Khalid\Desktop\New_folder\p*.csv"
  set "target=C:\Users\Khalid\Desktop\newfile.csv"
  
  rem remove output file if needed
  if exist "%target%" del "%target%" &gt;nul 2&gt;nul
  
  rem search for header row
  set "headerRow="
  for %%f in ("%source%") do (
      &lt;"%%~ff" ( for /l %%a in (1 1 10) do if not defined headerRow set /p 
        "headerRow=" )
          if defined headerRow goto haveHeader
      )
     :haveHeader
      if not defined headerRow (
         echo ERROR: impossible to get header row. 
          goto endProcess
  )
  
  rem output header to header file to use as filter.
  rem header is cut to avoid findstr limitations on search strings
  set "headerFile=%temp%\%~nx0_headerFile.tmp"
  setlocal enableextensions enabledelayedexpansion
  &gt; "%headerFile%" echo(!headerRow:~0,125!
  endlocal
  
  
  rem search for input files with matching headers to join to final file
  for /f "tokens=*" %%f in ('findstr /m /b /l /g:"%headerFile%" "%source%"') do (
      if not exist "%target%" (
  
              rem first file is directly copied
              copy "%%~f" "%target%" /y &gt; nul 2&gt;nul
  
          ) else (
  
              rem next files are filtered to exclude the header row
              findstr /v /b /l /g:"%headerFile%" "%%~f" &gt;&gt; "%target%"
      )
      echo ... [%%~ff] joined to %target%
  )
  
  rem remove the temporary header file
  del "%headerFile%" &gt;nul 2&gt;nul
  
  :endProcess
     endlocal
  </code></pre>