How to add filename to text file in a column

December 16, 2010 at 08:36:34
Specs: Windows Vista
I would like to add the filename to the content in a text file in a single column by using batch files. Can somebody please help? Thanks!

Here is an example of what I'd like to get.

Original text file contains:
*,1,1,0,0,0,0
*,1,2,0,0,0,0
*,1,3,0,1,0,1
*,1,4,0,1,1,1

I would like to change the text file (named as U128LN.txt) such that it contains the following.
*,1,1,0,0,0,0,U128LN
*,1,2,0,0,0,0,U128LN
*,1,3,0,1,0,1,U128LN
*,1,4,0,1,1,1,U128LN


See More: How to add filename to text file in a column

Report •


#1
December 16, 2010 at 14:52:20
If I understood well, I think that this code may be useful for you:


@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET FILENAME=%1
SET BASENAME=%~n1

FOR /F "delims=" %%a IN (%FILENAME%) DO (
ECHO %%a,%BASENAME%
)
ENDLOCAL
EXIT /B 0

Good Luck


Report •

#2
December 16, 2010 at 17:36:18
Sorry that I am very inexperienced in writing batch codes. Do I have to specify which file I would like to add a column in the coding? Thanks!

Report •

Related Solutions


Ask Question