Copy files into one file with filename using Batch
Hello, I want to copy some CSV files into one file, including the file name entry, for example:
hello.csv:
1; 2; 3
wolrd.csv:
4; 5; 6
You should get:
Datei.csv:
hello; 1; 2; 3
wolrd; 4; 5; 6
For copying data only
type *.csv >> data.csv
but I am missing the filename. Sorry, I am very new to Batch scripts. Bash is not a problem, but this should work on Windows
EDIT: To be more specific: I have a folder with these CSV files and I want each file to be copied into this form in one file!
+3
source to share
1 answer
@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 located.
+3
source to share