Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Best way of embedding data in a BTM file

May
120
1
I want to embed a list of files in my batch files. Can anyone suggest the best way of doing this?

Specifically, I have a series of filenames, and I want to create shortcuts for all of them. So something like

Code:
(for e in (@con) do SHORTCUT "%e" "" "" "" "Shortcuts\%@name[%e]") << EOF
App1\App1.exe
App2\App2.exe
App3\bin\App3.exe
EOF
would probably work, but it's pretty ugly if I need the SHORTCUT command to be any more complex.

Has anyone got any better suggestions? (I'm aware that one option is to have the exe names in a separate file, but I'm trying to see if there's a practical single-file solution, as that makes deployment somewhat easier).

Thanks,
Paul
 
I want to embed a list of files in my batch files. Can anyone suggest the best way of doing this?

Thanks,
Paul

Here is what I do. Let's say that I have a batch file called mybatch.btm. I start off the batch file with

Code:
goto jmp1
Next, I list the data items, whatever they may be;

Code:
[URL]http://text.www.weatheroffice.gc.ca/forecast/city_e.html?on-98&unit=m[/URL]
[URL]http://www.enigmaathome.net/top_users.php?sort_by=total_credit[/URL]
Another Data Item
Yet Another Data Item
Finally, I end the section with

Code:
:jmp1
Now, when I want to reference, oh, let's say, the second item, I do this,

Code:
echo %@line[mybatch.btm,2]
Basically, make the first statement of your batch file, which is line 0, jump over your data, then begin code execution. Your first line of data will be in line 1, second line of data will be in line 2, etc.

Note well that after writing your batch file, adding or removing a line of data will mess up the pointers to your data, so try and establish exactly how many data items you want before writing the batch file.

Joe
 
On Sat, 07 Aug 2010 15:46:01 -0400, Joe Caverly
<> wrote:

|---Quote (Originally by p.f.moore)---
|I want to embed a list of files in my batch files. Can anyone suggest the best way of doing this?
|
|Thanks,
|Paul
|---End Quote---

If you're simply going to hard-code the data into the batch file, you
could put each data entry onto a variable and accesss it by name.

set data1=foo
set data2=bar
...
set dataN=gadget
...
do i=1 to N
process %[data%i]
enddo

Or put them into an array.

setarray data[5]
set data[0]=foo
...
set data[4]=bar
...
do i=0 to 4
process %data[%i]
enddo
 
You could also create an array, store your data to each element, and reference each element of the array, thus;

Code:
@setlocal
@echo off
setarray adata[10]
set adata[0]=First Line Of Data
set adata[1]=Second Line Of Data
set adata[2]=Third Line Of Data
::
::
echo The first line is %adata[0]
echo The second line is %adata[1]
echo The third line is %adata[2]
unsetarray adata
endlocal
Joe
 
If you're simply going to hard-code the data into the batch file, you could put each data entry onto a variable and accesss it by name.

Or put them into an array.
Yes, that works. I hadn't thought of doing something like that, as I was focusing on just pasting the data in unchanged (what I'd do in a language with multi-line strings, or in a Unix shell script with a here-document). The nearest approach in TCC would be a here-document, but that doesn't seem to work as well in TCC as in Unix, for some reason (I think it's because of the way multi-line commands are parsed in TCC, but I'm not entirely sure...)

Thanks,
Paul.
 
On Sat, 07 Aug 2010 15:46:01 -0400, Joe Caverly
<> wrote:

If you're simply going to hard-code the data into the batch file, you
could put each data entry onto a variable and access it by name.

This is true. The reason that I place unmanaged data in a batch file directly is due to having redirection or piping symbols in the needed data, such as certain URLs.

I then use the @safeline function from the safechars plugin to process the unmanaged data.

I find this the easiest method, since I would have to SETDOS /X-57 before setting variables containing redirection or piping symbols, and then SETDOS /X0 afterwards.

As the original request did not require such a need, you are correct in that setting an environment variable is the best solution.

Joe
 
I want to embed a list of files in my batch files. Can anyone suggest the best way of doing this?

Specifically, I have a series of filenames, and I want to create shortcuts for all of them. So something like

Code:
(for e in (@con) do SHORTCUT "%e" "" "" "" "Shortcuts\%@name[%e]") << EOF
App1\App1.exe
App2\App2.exe
App3\bin\App3.exe
EOF
would probably work, but it's pretty ugly if I need the SHORTCUT command to be any more complex.

You could also

Code:
gosub sub <<- EOF

and put whatever you like in the subroutine; a DO LINE IN @CON might be nice.
 
> Here is some rough code
> (http://www.jpsoft.com/forums/showthread.php?t=2241) to do what you
> want.


Wouldn't %_batchline be an easier way to find start and end of the
data section? Put the data in a text / endtext block, so it doesn't
get executed. Surround it with %_batchline to get startline (+2) and
endline (-2) of the data. Then use @line in a loop to read.

Best Regards,

* Klaus Meinhard *
<www.4dos.info>
 
Wouldn't %_batchline be an easier way to find start and end of the
data section? Put the data in a text / endtext block, so it doesn't
get executed. Surround it with %_batchline to get startline (+2) and
endline (-2) of the data. Then use @line in a loop to read.

Best Regards,

* Klaus Meinhard *
<www.4dos.info>

Hi,
Another option was to just place the desired text at the end of the batch file, and loop backwards from the end of the file, until I reached a blank line. TCC does not give an error when unmanaged text is placed in the batch file in this manner.

You can even place </www.4dos.info>unmanaged<www.4dos.info> text between subroutines, and still get no error, while the program works as it should.

Example:
</www.4dos.info>
Code:
echo Hello
quit

:one
return

This does not give an error

:two
return

:three
return

This is the second last line of the batch file
This is the last line of the batch file, with no error
<www.4dos.info>
I felt that placing unmanaged text in a sub was a more structured method of containing the data.

I thought about using the %_batchline variable as a pointer, but since the batchfile itself is dynamic, the line(s) containing the unmanaged text would not remain static.

Joe

</www.4dos.info>
 
I want to embed a list of files in my batch files. Can anyone suggest the best way of doing this?

Specifically, I have a series of filenames, and I want to create shortcuts for all of them. [ . . . deletion . . . ]

Has anyone got any better suggestions? (I'm aware that one option is to have the exe names in a separate file, but I'm trying to see if there's a practical single-file solution, as that makes deployment somewhat easier).

I write a lot of batch files, and many times I need to embed data in a batch file without having an external data file. This is a trick I do a lot:

Code:
:: REM - Overwrite any file of this name that already exists
TEXT [B]>tempfile[/B]
c:\path\to\file1
c:\another\path\to\file2
or some other data here ...
ENDTEXT
Then I use whatever tools and arguments I like to address tempfile, which was created on the fly.

I normally delete tempfile at the end of the batch file when done. You have all the benefits of a truly external file, but none of the muss or fuss. HTH.
 
*** VN.BTM ***
: [HKEY_CURRENT_USER\Environment]
: [HKEY_CURRENT_USER\Volatile Environment]
: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment]
do _r=0 to 2
reg query
%@quote[%@strip["]",%@field["[",1,%@line[%@name[%0].btm,%_r ]]]]
enddo
*** EOF ***

Example of embedded data in a batch file. This reads the first three lines
starting at "0" ending at "2
of the running batch file. I have notice all version of 4nt up to tcc12 all
get lost if there are tabs/spaces after
embedded data


> -----Original Message-----
> From: p.f.moore
> Subject: [Support-t-2237] Best way of embedding data in a BTM file
>
>
> I want to embed a list of files in my batch files. Can anyone
> suggest the best way of doing this?
>
> Specifically, I have a series of filenames, and I want to create
> shortcuts for all of them. So something like
>
>
> Code:
> ---------
> (for e in (@con) do SHORTCUT "%e" "" "" "" "Shortcuts\%@name[%e]") << EOF
> App1\App1.exe
> App2\App2.exe
> App3\bin\App3.exe
> EOF
> ---------
> would probably work, but it's pretty ugly if I need the SHORTCUT
> command to be any more complex.
>
> Has anyone got any better suggestions? (I'm aware that one option
> is to have the exe names in a separate file, but I'm trying to
> see if there's a practical single-file solution, as that makes
> deployment somewhat easier).
>
> Thanks,
> Paul
 

Similar threads

Back
Top