@echo off setlocal set first=1 >new.txt.tmp ( for %%F in (*.txt) do ( if defined first ( type "%%F" set "first=" ) else more +1 "%%F" ) ) ren new.txt.tmp merged.csv for /r %%a in (merged.csv) do for %%b in ("%%~dpa\.") do ren "%%~a" "%%~nxb%%~xa"