I am new here and to batch scripting, trying to learn.

I have a batch that adds an extension to each string in a text file but what I have right now, it leaves a space before the extension.

@echo off 
set addtext=.mp4
for /f "delims=*" %%a in (list.txt) do (echo(%%a%%a%addtext%)>>new_list.txt

Any help is much Apppreciated!

To remove trailing white spaces I used a helper batch called JREPL.BAT and this command in another batch file

call jrepl " +$" "" /f list.txt /o -

Thank You for the Help!

  • Have you ensured there's no trailing spaces on each line of the list.txt file? – Ƭᴇcʜιᴇ007 May 5 '17 at 19:30
  • How would I be able to verify that considering there is no extensions to determine the correct end of the string? – Todd Thomas May 5 '17 at 19:35
  • I believe there are spaces at the ends of the strings, when I click on a string, it's always 1 space too far. How would you eleminate that space? – Todd Thomas May 5 '17 at 19:38
  • First, manually remove them from a test-variation of list.txt, and test. – Ƭᴇcʜιᴇ007 May 5 '17 at 19:40
  • That Worked! Now I gotta do this for over 1000 strings... – Todd Thomas May 5 '17 at 19:42

Ensure the list.txt files doesn't contain trailing whitespaces on the lines.

If it does, and if you want to have the batch file also trim trialing whitespace, check out this existing StackOverflow question:


Depending on your input file (no <>|&^) , this batch could do:

@Echo off
Type NUL >new_list.txt
for /F "delims=" %%a in (list.txt) do Call :Write %%a
Goto :Eof
>>new_list.txt Echo:%*

The %* will trim all leading and trailing spaces from the input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.