@ECHO OFF
SETLOCAL enabledelayedexpansion
SET "sourcedir=c:\testso\sourcedir"
SET "destdir=c:\testso\destdir"
SET "outfile=%destdir%\outfile.txt"
:: remove variables starting #
FOR /F "delims==" %%a In ('set # 2^>Nul') DO SET "%%a="
FOR /f "delims=" %%e IN (
'dir /b /a-d "%sourcedir%\*.csv" '
) DO (
rem one more file found
set /a #line=10000
for /f "usebackqdelims=" %%y in ("%sourcedir%\%%e") do (
set /a #line+=1
for %%o in (!#line!) do set "#data%%o=!#data%%o! %%y"
)
)
(
for /f "tokens=1*delims== " %%b in ('set #data') do echo %%c
)>"%outfile%"
GOTO :EOF
The first part of the code sets the directories to be used and the output filename. The values I've used suit my test system; change to suit yourself
Next, remove all variables that start # from the environment.
Then find all the .csv files in the source directory. Naturally, you could change the filemask * to suit.
With each filename found, start a counter. I used a high number so that the data will arrive in variables #data10001, etc.
Read each line of the current file in %%e. The entire line contents because of the delims= and the usebackq is required because the filename is quoted.
for each line, bump the line number and append the line contents to #datathelinenumber by first placing the current line number in %%o to take advantage of cmd's parsing methodology.
Finally, all of the data read from the files will be in #data10001, #data10002, so use set to list the data in order, and select the set output after the = and space.
Note that this requires that the files all have the same number of lines, and the lines all contain some data.
The sequence of the columns would be the same as the sequence of the files listed by the dir command.