Windows – Add text to beginning and end of each line using batch/cmd

batchcommand lineregexwindows

What I'd like to achieve in the end is to generate a text file that lists all *.txt files in the current directory with the path appended to the beginning of the filenames, and some other string after the filenames.

ie.

C:\path\first.txt string

C:\path\second.txt string

C:\path\third.txt string

As of now all I can think of is to use

dir /b *.txt

and some sort of regex code to append the strings, but unsure how to. If it matters, the path and string at the end are the same for all lines.

Thank you!

Best Answer

Create a batch file e.g:

script.bat:

@echo off
for %%i In (*.txt) DO echo %CD%\%%i string

then simply run script.bat from the directory where you want to list the files and append the string

Related Question