add text before and after batch output?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

add text before and after batch output?

#1 Post by tlm2408 » 25 Sep 2017 06:21

I have a batch fille that lists all files in a folder and saves them to a text file.

Is there any way I can add some text (javascript) before it prints the list and some more after it?

So I'm trying to do this.

multiple lines of javascript at the begining of the file
the list of files returned from the batch file
some more lines javascript at the end of the file

This is the batch file I have that lists the files:

Code: Select all

@echo off &setlocal
>"list.txt" type nul
for /r "C:\Photos" %%i in (*.jpg *.bmp) do (
  set "fname=%%~nxi"
  set "fpath=%%~fi"
  setlocal EnableDelayedExpansion
>>"list.txt" echo "!fname!" "!fpath:\=/!"
  endlocal
)


Pretty new to batch files so any help would be greatly appreciated.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: add text before and after batch output?

#2 Post by penpen » 25 Sep 2017 08:56

Just do it in the same way you have added the file list:
Use echo and redirect the output to append to the file before and after the for loop.

Code: Select all

>>"list.txt" echo var add="some javascript text";


penpen

tlm2408
Posts: 31
Joined: 01 Aug 2017 01:19

Re: add text before and after batch output?

#3 Post by tlm2408 » 25 Sep 2017 15:37

Thank you very much Penpen. Works great!!!

Post Reply