1.

Solve : Multi-Line file to Variable ...?

Answer»

Hello all,

Am trying to GET the contents of a file into a variable.
FILE CONTAINS: (but could be anything)
[highlight]sql-job-1.sql
sql-job-2.sql
sql-job-3.sql[/highlight]

Need to get it into a Variable like ... [highlight]sql-job-1.sql,sql-job-2.sql,sql-job-3.sql[/highlight] ... if possible.

The purpuse is to include the list from the file into the body of an email ....
set MailBody=The %Product% Instance `%Instance%` has performed one or more SQL updates/query's against the database `%SQLDatabase%`. Please refer to the individual logfiles for each of the following ... [highlight]%SQLLOGLIST%[/highlight] with regards to their success.

Hope I've provided enough of an explaination.
Note: DOS batch script indicdently uses SETLOCAL ENABLEDELAYEDEXPANSION .
Many THANKS in advance.
This might help:

CODE: [Select]@echo off
setlocal enabledelayedexpansion
set str=
for /f %%i in ([highlight]input.txt[/highlight]) do set str=!str! %%i,
echo %str%

The HIGHLIGHTED portion is a arbitrary file name.

Good luck. 8-)

Many thanks Sidewinder - figured you'd be the one to respond.
I'd actually had everything ~but~ the preceeding 'set str=', thinking it was not necessary - why, oh why.
The script I've written for work has been an eye opener (using `setlocal enabledelayedexpansion`) and have had to remember at what level of the script the executing code is to determine which operators (% / !) (if that's what you call them) to use.

Again, many thanks.The set str= is defensive coding. You never know what user environment variables have been defined previously.

Glad it it WORKED for you. Stop by any time. 8-)



Discussion

No Comment Found