Reputation: 33
Hello I want to copy some .csv files into one file including an entry with the filename, like:
hello.csv:
1; 2; 3
wolrd.csv:
4; 5; 6
Should result in:
Datei.csv:
hello; 1; 2; 3
wolrd; 4; 5; 6
For only copying the data
type *.csv >> data.csv
work but I am missing the filename. Sorry I am very new to Batch scripts. Bash would be no problem, but this has to work on Windows
EDIT: To be more specific: I have a folder with this .csv files and I want every file to be copied in this form into one file!
Upvotes: 3
Views: 186
Reputation: 57302
@echo off
set "root_dir=c:\csv_files"
pushd "%root_dir%"
del /q /f united.csv >nul 2>&1
break>united.tmp
for %%# in (*.csv) do (
echo %%#
for /f "usebackq tokens=* delims=" %%a in ("%%#") do (
(echo(%%#;%%a)
) >>united.tmp
)
move united.tmp united.csv
Change root_dir to the directory where the csv files are.
Upvotes: 3