I've created a batch program to merges all the .txt files in a directory into one txt file. What I would like to do is add the file names to a field within the txt files. For example
121101
121102
121103 will be my files
these are dates
(Nov 1 , Nov 2, Nov 3)My files have no date assigned within the text file. How can I add the Nov 1- 2012 field into 121101?
Is it easier to do before my merging batch program?
copy *.txt merged.txt currently is my batch
@echo off for %%j in (*.txt) do for /F "delims=" %%k in (%%j) do echo.%%~nj,%%k>> merged.new ren merged.new merged.txt
This works, but it puts blank lines between the contents and the names:
type *.txt > merged.txt 2>&1
This could also work, but may be slow:@echo off>merged.txt
for %%a in (*.txt) do (
>>merged.txt echo %%a
copy merged.txt+%%a
)
::==== end batch
Depends on what you mean by "adding the field." If you just want to inject the file name before its contents in the merged file, something like this will do. type *.txt > merged.out 2>&1
Thanks for the replies guys.
That last command does add the file name to the beginning of the original text file.
What I meant by adding a field wasCurrently i have this in the original text file 110112
data
data
datawhat i was wanting to have is
110112,data
110112,data
110112,data
or
data,110112
data,110112
data,110112adding the file name at the end of each row/record or beginning of one. Isn't there an append function or something?
@echo off for %%j in (*.txt) do for /F "delims=" %%k in (%%j) do echo.%%~nj,%%k>> merged.new ren merged.new merged.txt
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |