Windows Batch file execution error -
i trying run batch file concatenate csv files pattern contracteligibility_*
in working folder.they of same format , need concatenate without repeating header.
the code 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\ /f "tokens=*" %%a in (c:\users\kartikeya.avasthi\desktop\batch_scripts\dirfiles.txt) ( set /p header=<%%a echo !header!>combined.csv ) /f "tokens=*" %%a in (c:\users\kartikeya.avasthi\desktop\batch_scripts\dirfiles.txt) ( more +1 %%a>>combined.csv ) del dirfiles.txt
it concatenates fine getting "echo off " @ start of file first line. know first loop (the 1 in bold) responsible passing null value in variable header. files in set path. can me solve problem. placing drop after echo not acceptable batch file followed automated load utilizes created file combined.csv
.
the equivalent code below solve problem, run faster, , looks cleaner...
@echo off setlocal enabledelayedexpansion cls cd c:\users\kartikeya.avasthi\desktop\batch_scripts\ set "header=" (for %%a in (contracteligibility_*.csv) ( if not defined header ( set /p header=<%%a echo !header! ) more +1 %%a )) > combined.csv
Comments
Post a Comment