add a string to .txt file based on file name

November 24, 2011 at 02:50:29
Specs: Windows XP
I have about 300 txt files and every file is very long about 5000 lines.
I need to add the name of .txt file to its contents , at the beginning of every line.


For ex. TextFile1.txt
I want to add "TextFile1" at the beginning of every line in this TextFile1.txt.

Any help?


See More: add a string to .txt file based on file name

Report •

#1
November 24, 2011 at 03:23:06
@echo off
pushd Your_Directory
for %%i in (*.txt) do for /F "delims=" %%j in ('type "%%i"') do echo.%%i %%j>> "%%~ni.new"
del *.txt
ren *.new *.txt
popd

________

Report •

#2
November 24, 2011 at 03:59:12
Thanks.
It works. But one more simple question. Can I put the FileName in "", ie. like
"TextFile1.txt" ?


Report •

#3
November 24, 2011 at 06:22:16
Of course, just replace echo.%%i witn echo."%%i".

Report •
Related Solutions


Ask Question