Pages: 1
RSS
Extracting an email address from a file name
 
On theBat! forum I asked if theBat! could extract an email address from a file name, and send the file to that address, if the file name was email@emailaddress.com.txt.

I was kindly provided 2 files, sendfile.cmd and sendfile.tpl (shown below) and they worked successfully. Thak you.

Now I am hoping I can get some help with theBat! to extract the email address, from a file name, that contains more than just the email address. The files have a name seperated by ~~ followed by the email address and then the extension. Here is an example of a file name:
myLifeStory~~email@emailaddress.com.txt

Can theBat! extract the email address from a file name of this type and place the email address into the TO; line, and send it just as the files below accomplish?

My main question here is: Can the file(s) below be modified to extract only the info that apppears between ~~ and .txt? (and place it in the TO: line? etc.

Thank you. I look forward to your assistance.

Sendfile.cmd
For %%i in ("C :\Documents and Settings\My Documents\Output\*.txt") do "C:\Program Files\The Bat!\thebat.exe" /MailT="C:\Documents and Settings\My Documents\Output\Sendfile.tpl";A="%%i";To="%%i";S=¬"¬%%i";Send

Sendfile.tpl
And a sendfile.tpl, as template. Containing this:
-----Start of Sendfile.tpl-------------¬
%SetPattRegExp='C :\Documents and Settings\My Documents\Output\(.*?)\.txt'%-
%RegExpBlindMatch='%To'%-
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='1')%-
Hi %ABToFirstName="%ToFName",
 
Sure, should be possible.

Try something like this in your .tpl file:

%SetPattRegExp='(.*?)~~C:\Documents and Settings\My Documents\Output\(.*?)\.t­xt'%-
%RegExpBlindMatch='%To'%-­
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='2­')%-
Hi %ABToFirstName="%ToFName"­,

That's two minor changes in the regular expression that extracts the address.

I didn't test this though.
__________________________________
I'm just a user of The Bat! I don't work for Ritlabs.
 
Thank you again for your assistance.
Glad to hear "should be possible".

I did try your recommendation without success.

You said "two minor changes in the regular expression"
which I believe are (.*?) and ~~, but I also see the SubPath='2' is different from the original SubPath='1'.

I have tested it both ways without success.

I would be very eager and happy to test another solution that you may suggest.

This what the file currently looks like:

%SetPattRegExp='(.*?)~~C:\\Documents and Settings\\My Documents\\Ouput\\(.*?)\.txt'%-
%RegExpBlindMatch='%To'%-
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='2')%-
Hi %ABToFirstName="%ToFName",

Thank you

Regards, %FromFName



Thanks again. I look forward to your reply.
 
I shouldn't post when I'm supposed to sleep. The extra part is supposed to get before the filename, not before the path.
Try:
%SetPattRegExp='C:­\\Documents and Settings\\My Documents\\Ouput\\(.*?)~~(.*?)\.­txt'%-
%RegExpBlindMatch='%To'%-­
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='2­')%-

%SubPatt='2' because the address is now the second subpattern.
__________________________________
I'm just a user of The Bat! I don't work for Ritlabs.
 
You are remarkable, even when you are too tired to post. Thank you. Your last solution was successful.
Much thanks again.
Pages: 1