I am trying to run a batch file to concatenate all csv files with the pattern ContractEligibility_*
in the working folder.They are all of the same format and i need to concatenate without the repeating header.
The code is as follows:
@echo off>Combined.csv
cls
setlocal enabledelayedexpansion
if exist C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\Combined.csv del C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\Combined.csv
dir /a-d /b C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\ContractEligibility_*.csv>C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\dirfiles.txt
cd C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\
for /f "tokens=*" %%A in (C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\dirfiles.txt) do (
set /p header=<%%A
echo !header!>Combined.csv
)
for /f "tokens=*" %%A in (C:\Users\kartikeya.avasthi\Desktop\Batch_Scripts\dirfiles.txt) do (
more +1 %%A>>Combined.csv
)
del dirfiles.txt
it concatenates fine but I am getting an "Echo is off " at the start of the file as the first line.
I know that the first for loop (The one in bold) is responsible as it is passing null value in the variable header. All the files are in the set path.
Can someone help me solve the problem. Placing a drop after the echo is not acceptable as the batch file is followed by an automated load which utilizes the created file combined.csv
.