Discussion:
Can Blat be used when name of the attached file is unknown?
(too old to reply)
manfred.winter@yahoo.com [blat]
2017-06-03 08:13:01 UTC
Permalink
We have a POS Program that creates .txt Files with sales results at the End of Day Routine. These Files have names like Print2070602.txt.
I would like to see if we can send Emails with Blat by pointing to the directory, f.i. C:\POS\PrintFIles\ with some kind of a Wildcard (*.txt). Looks like this is not supported. Any idea how to succeed?

The command line blat :C\POS\Printfiles\*.txt results in 'unknown error code 123 when trying to open C:\POS\PrintFiles\*.txt
'Chip' chip.programmer@att.net [blat]
2017-06-04 02:46:11 UTC
Permalink
Post by ***@yahoo.com [blat]
We have a POS Program that creates .txt Files with sales results at the
End of Day Routine. These Files have names like Print2070602.txt.
I would like to see if we can send Emails with Blat by pointing to the
directory, f.i. C:\POS\PrintFIles\ with some kind of a Wildcard (*.txt).
Looks like this is not supported. Any idea how to succeed?
The command line blat C:\POS\Printfiles\*.txt results in 'unknown error
code 123 when trying to open C:\POS\PrintFiles\*.txt
You can send attachments with a wildcard, but when sending as a message
body. The problem for me would be how to send multiple files as the message
body when there exists more than one file which matches the wildcard string.

This line is a start to get your print files sent. You still need the -to
and -subject entries as a minimum.

Blat - -body "Here are today's print files." -attach C:\POS\Printfiles\*.txt
--
Chip
Manfred Winter manfred.g.winter@gmail.com [blat]
2017-06-04 03:24:22 UTC
Permalink
Thanks.
That is doable. Still would prefer the text to appear in the message body though.
The POS application itself takes care that older printfiles will be deleted or moved to another directory, so this is nothing to worry about.
I tried successfully to rename the original print file on the batch i use to call Blat. That's basically working, but in order to use it I'd love to be able to add a string for current Date in the Subject line.


Sent from the road
Post by 'Chip' ***@att.net [blat]
Post by ***@yahoo.com [blat]
We have a POS Program that creates .txt Files with sales results at the
End of Day Routine. These Files have names like Print2070602.txt.
I would like to see if we can send Emails with Blat by pointing to the
directory, f.i. C:\POS\PrintFIles\ with some kind of a Wildcard (*.txt).
Looks like this is not supported. Any idea how to succeed?
The command line blat C:\POS\Printfiles\*.txt results in 'unknown error
code 123 when trying to open C:\POS\PrintFiles\*.txt
You can send attachments with a wildcard, but when sending as a message
body. The problem for me would be how to send multiple files as the message
body when there exists more than one file which matches the wildcard string.
This line is a start to get your print files sent. You still need the -to
and -subject entries as a minimum.
Blat - -body "Here are today's print files." -attach C:\POS\Printfiles\*.txt
--
Chip
'Chip' chip.programmer@att.net [blat]
2017-06-04 17:25:54 UTC
Permalink
Post by Manfred Winter ***@gmail.com [blat]
Post by 'Chip' ***@att.net [blat]
Post by ***@yahoo.com [blat]
We have a POS Program that creates .txt Files with sales results at the
End of Day Routine. These Files have names like Print2070602.txt.
I would like to see if we can send Emails with Blat by pointing to the
directory, f.i. C:\POS\PrintFIles\ with some kind of a Wildcard (*.txt).
Looks like this is not supported. Any idea how to succeed?
The command line blat C:\POS\Printfiles\*.txt results in 'unknown error
code 123 when trying to open C:\POS\PrintFiles\*.txt
You can send attachments with a wildcard, but when sending as a message
body. The problem for me would be how to send multiple files as the
message body when there exists more than one file which matches the
wildcard string.
This line is a start to get your print files sent. You still need the -to
and -subject entries as a minimum.
Blat - -body "Here are today's print files." -attach
C:\POS\Printfiles\*.txt
Thanks.
That is doable. Still would prefer the text to appear in the message body though.
The POS application itself takes care that older printfiles will be
deleted or moved to another directory, so this is nothing to worry about.
I tried successfully to rename the original print file on the batch i use
to call Blat. That's basically working, but in order to use it I'd love to
be able to add a string for current Date in the Subject line.
If you can use a batch file for sending emails, then it is easy to use
wildcards for the message body. It is also very easy to add the date to
your subject line. Here is a simple batch line to give you both items you
desire:

for %%f in (C:\POS\Printfiles\*.txt) do Blat.exe %%f -to somebody -subect
"Here is the Point Of Sale print file for %DATE%"
--
Chip
manfred.winter@yahoo.com [blat]
2017-06-05 05:32:08 UTC
Permalink
Thanks. That was helpful. But it seems I need to do some more to cover all cases, especially Errors.


First, let me explain a bit:
The POS Program stores a .txt File with the results in a specified Folder. The name of this file is printfile20170604.txt, where 20170604 does not refer to the date of file creating, but rather to the "Rundate" of the POS. Example is a Bar which closes at 02 AM. The "Rundate" for this Day is still the date of the opening, say the Bar opens on June 4th 6 pm, and closes June 5th 2 AM.
"Rundate" now refers to opening Date.
This can become very important in cases where the operation closes around Midnight, as the creation date would here be misleading, depending on whether it closes a few Minutes before or after Midnight.
I have now managed to create a working batch file with the following structure (This one does not yet take the possibility of several *.txt files into consideration, more on this later!)


REN C:\Bartender\Printfiles\*.txt result.txt
C:\POS\Blat\blat.exe C:\POS\PrintFiles\result.txt -tf C:\POS\Blat\recipients.txt -cf C:\POS\blat\ccrecipients.txt -bf C:\POS\Blat\bccrecipients.txt -subject "Your Sales Results from %1" -sig C:\POS\blat\sig.txt -debug -log C:\POS\Blat\log.txt
MOVE C:\Bartender\Printfiles\*.txt C:\Bartender\PrintFiles\Archive\

This file is invoked by the POS Program at successful End of Day routine, and the %1 in the Subject line refers to a parameter consisting of the RUNDATE in Numbers Format (YYYYMMDD) which is passed by the Application to a Batch File named EODEND.BAT.
So far so good, and with your FOR ..DO structure I could extend it for the case of more than one File present.(Which is only possible because of an Error within blat, maybe email server or most likely Interent down)
Trouble looms when Errors happen ...
In case of an ERROR of the POS then Blat wont be called, and we have to fix the underlying Error. No an issue we need to discuss here.
But what if the Internet is down?
Blat won't be able to send the File. And the File will be deleted from the Folder.
Here I need to build in some Error handling.
I am thinking of another blat.exe instance EVERYHOUR.BAT that is invoked maybe every hour by Windows Task Scheduler. In normal procedure there won't be any .txt file in the folder, so this task will just quit.
But in the case of an error due to Internet or Mail Server issues in the Original EODEND.BAT, I need EODEND.BAT to exit without running the last command which deletes the .txt File. And then the Batch invoked by Task Scheduler will finally take care of it once Internet is back.As this can take more than one day, there will be more than one .txt file so a FOR .. DO can come handy here. But the %1 won't be available.
Possible Solution: The EVERYHOUR,BAT will use -attach rather and the Subject line will look like: Recovered Sales Results sent %DATE%

What do you think? And how can I modify the Batch Files for correct Error handling?


Thanks a lot for your help!
'Chip' chip.programmer@att.net [blat]
2017-06-06 23:35:01 UTC
Permalink
After Blat executes, you can check errorlevel for problems with Blat.

For example:


for %%f in (C:\Bartender\Printfiles\*.txt) do call :procFile %1 %%f
goto :eof

:procFile
C:\POS\Blat\blat.exe %2 -tf C:\POS\Blat\recipients.txt -cf C:\POS\blat\ccrecipients.txt -bf C:\POS\Blat\bccrecipients.txt -subject "Your Sales Results from %1" -sig C:\POS\blat\sig.txt -debug -log C:\POS\Blat\log.txt
if errorlevel 1 goto :eof
MOVE %2 C:\Bartender\PrintFiles\Archive\

:eof



In this example shown above, an error level value of zero will execute the MOVE command; zero indicates success. Any value other than zero will be an error and go directly to the label :eof that follows the MOVE command. All values returned from Blat will be positive, with zero being the lowest value.

The other thing about the example above is that it takes care of multiple files. Windows batch files can call internal labels as if calling an external program. The example above does that, it calls the internal label :procFile for each file found in your Printfiles folder that has .txt extension. The first argument given to the internal label is still the RUNDATE you mentioned, but the second argument passed to this internal label is the filename found in Printfiles folder.

Chip



From: mailto:***@yahoogroups.com
Sent: Sunday, June 04, 2017 11:32 PM
To: ***@yahoogroups.com
Subject: Re: [blat] Can Blat be used when name of the attached file is unknown?



Thanks. That was helpful.
But it seems I need to do some more to cover all cases, especially Errors.

First, let me explain a bit:
The POS Program stores a .txt File with the results in a specified Folder. The name of this file is printfile20170604.txt, where 20170604 does not refer to the date of file creating, but rather to the "Rundate" of the POS. Example is a Bar which closes at 02 AM. The "Rundate" for this Day is still the date of the opening, say the Bar opens on June 4th 6 pm, and closes June 5th 2 AM.
"Rundate" now refers to opening Date.
This can become very important in cases where the operation closes around Midnight, as the creation date would here be misleading, depending on whether it closes a few Minutes before or after Midnight.
I have now managed to create a working batch file with the following structure (This one does not yet take the possibility of several *.txt files into consideration, more on this later!)


REN C:\Bartender\Printfiles\*.txt result.txt
C:\POS\Blat\blat.exe C:\POS\PrintFiles\result.txt -tf C:\POS\Blat\recipients.txt -cf C:\POS\blat\ccrecipients.txt -bf C:\POS\Blat\bccrecipients.txt -subject "Your Sales Results from %1" -sig C:\POS\blat\sig.txt -debug -log C:\POS\Blat\log.txt
MOVE C:\Bartender\Printfiles\*.txt C:\Bartender\PrintFiles\Archive\

This file is invoked by the POS Program at successful End of Day routine, and the %1 in the Subject line refers to a parameter consisting of the RUNDATE in Numbers Format (YYYYMMDD) which is passed by the Application to a Batch File named EODEND.BAT.
So far so good, and with your FOR ..DO structure I could extend it for the case of more than one File present.(Which is only possible because of an Error within blat, maybe email server or most likely Interent ! down)
Trouble looms when Errors happen ...
In case of an ERROR of the POS then Blat wont be called, and we have to fix the underlying Error. No an issue we need to discuss here.
But what if the Internet is down?
Blat won't be able to send the File. And the File will be deleted from the Folder.
Here I need to build in some Error handling.
I am thinking of another blat.exe instance EVERYHOUR.BAT that is invoked maybe every hour by Windows Task Scheduler. In normal procedure there won't be any .txt file in the folder, so this task will just quit.
But in the case of an error due to Internet or Mail Server issues in the Original EODEND.BAT, I need EODEND.BAT to exit without running the last command which deletes the .txt File. And then the Batch invoked by Task Scheduler will finally take care of it once Internet is back.As this can take more than one day, there will be more than one .txt file so a FOR .. DO can come handy here. But the %1 won't be available.
Possible Solution: The EVERYHOUR,BAT will use -attach rather and the Subject line will look like: Recovered Sales Results sent %DATE%

What do you think? And how can I modify the Batch Files for correct Error handling?

Thanks a lot for your help!
manfred.winter@yahoo.com [blat]
2017-06-08 07:30:44 UTC
Permalink
Thanks. That was helpful indeed!
Now I am only stuck with Variables inside a FOR DO loop ...

I know that this is beyond the scope of this group, but, as the results I get while attempting to resolve this issue also seem to confuse Blat, I post this follow-up now.

Here is the Situation and what I want to achieve:
Folder C:\POS\PrintFiles contains one or several .txt files. The text files have the Rundate in their names, i.e. Print201706.txt, Print201707.txt and so on.
I want to use Blat now to send one mail for each of the found printYYYYMMDD.TXT files, with the Date Part of the Filename as Part of the Subject Line, and the Text File in the Message Body.
I need to do a For DO loop here:
FOR 55f in(C:\POS\PrintFiles\Print*.txt DO
(C:\POS\Blat\blat.exe %%f -tf "C:\POS\Blat\recipients.text" -subject "Your ales Results from (_Replace these words here with correct Syntax:The Substring of the current file of the loop which represents the Date in numbers format YYYYMMDD_) -sig "C:\POS\Blat\sig.txt -log C:\POS\Blat\log.txt"
)

In case I use %%f as placeholder in the -Subject line, I get the expected result:
My Subject is "Your Results from C:\POS\PrintFiles\Print20170608.txt".
Correct, but not very helpful.
The Substring command to receive 20170608 from the full filename is %VARIABLE:~34,8%. But the Subsitution seems to be not working! The :~34,8 just gets appended to the Subject String ...

What am I doing wrong here?
'Mike Mattos' mmattos@rogers.com [blat]
2017-06-08 11:56:19 UTC
Permalink
http://www.dostips.com/DtTipsStringManipulation.php



Mike Mattos



“To succeed in the world it is not enough to be stupid, you must also be well-mannered”



Voltaire



From: ***@yahoogroups.com [mailto:***@yahoogroups.com]
Sent: June 8, 2017 3:31 AM
To: ***@yahoogroups.com
Subject: Re: [blat] Can Blat be used when name of the attached file is unknown?





Thanks. That was helpful indeed!
Now I am only stuck with Variables inside a FOR DO loop ...

I know that this is beyond the scope of this group, but, as the results I get while attempting to resolve this issue also seem to confuse Blat, I post this follow-up now.

Here is the Situation and what I want to achieve:
Folder C:\POS\PrintFiles contains one or several .txt files.

The text files have the Rundate in their names, i.e. Print201706.txt, Print201707.txt and so on.
I want to use Blat now to send one mail for each of the found printYYYYMMDD.TXT files, with the Date Part of the Filename as Part of the Subject Line, and the Text File in the Message Body.
I need to do a For DO loop here:
FOR 55f in(C:\POS\PrintFiles\Print*.txt DO
(C:\POS\Blat\blat.exe %%f -tf "C:\POS\Blat\recipients.text" -subject "Your ales Results from (_Replace these words here with correct Syntax:The Substring of the current file of the loop which represents the Date in numbers format YYYYMMDD_) -sig "C:\POS\Blat\sig.txt -log C:\POS\Blat\log.txt"
)

In case I use %%f as placeholder in the -Subject line, I get the expected result:
My Subject is "Your Results from C:\POS\PrintFiles\Print20170608.txt".
Correct, but not very helpful.
The Substring command to receive 20170608 from the full filename is %VARIABLE:~34,8%. But the Subsitution seems to be not working! The :~34,8 just gets appended to the Subject String ...

What am I doing wrong here?
manfred.winter@yahoo.com [blat]
2017-06-09 06:05:15 UTC
Permalink
Thanks. Dug deep into the ancient art of batch processing and finally resolved the matter.

Lots of thanks to all who helped out!

Continue reading on narkive:
Loading...