Pages: 1
RSS
Can TB move a file, and send a link to it?
 
Can TheBat! automatically move a file to a subdirectory and then mail a link to that subdirectory file?
Presently, the files have the users email address as part of the file name.
A file name example is: joe@hotmail.com~~myLifeStory.txt.
I am currently using to files that extract the email address from the file name, attach the file and send the attachment.

I’m using sendFile.cmd:
For %%i in ("C:\BAT\TA\*.txt") do "C:\Program Files\The Bat!\thebat.exe" /MailT="C:\BAT\Sendfile.tpl";A="%%i";To="%%i";Send

And sendfile.tpl:
%SetPattRegExp='C:\\BAT\\TA\\(.*?)~~(.*?)\.txt'%-
%RegExpBlindMatch='%To'%-
%ModifyOnce(To)%-
%SetHeader(To,%SubPatt='1')%-
%Subject="Hello"
Hi %ABToFirstName="%ToFName",

Thank you.
Regards, %FromFName

Instead of sending the file, can I get some help so that TheBat! can automatically move the file to a subdirectory (named with the email address name – already created), and send a link to the file via the email address? Thank you.
 
do you want to email someone a link to a file on your local hard disk?

If so, this will not work, unless the recipient reads the email on the same computer. When the message is received on another computer, the link will point to a (non-existing)file on that other computer, not to the file on your computer. Unless, of course, your computer is a server with a real IP that others can access via internet, but in that case you should transform the local path to a http:// url (or to \\server\share url, if the recipient is in the same LAN and can access shared folders on your PC)

Maybe I misunderstood.  
 
Thank you for your reply. You did not misunderstand, the problem was, I was not not clear enough with my message, my apology. Yes, it is on a server via http://url.

So, can a .cmd or .tpl be created to accomplish the link? using theBat!  
 
I would do this with a .vbs file which iterates through all .txt files in a given dir, parses filename to determine recipient etc., moves the file to another dir, converts new local path to a valid URL, and then creates a temporary template file. Then sends a command to theBat to send the message.

With .vbs files it's very easy to perform file operations and string manipulation. Probably the same can be achieved with .bat/.cmd but I'm not very good with these and don't know how to deal with strings, if possible at all.
 
here is a vbs script I quickly adapted from one of the scripts I use with theBat. Save as a file with a .vbs extension

Code
'---- EDIT HERE -------------------------------
myDir = "C:\\test"
baseUrl = "http://server/test/"
'
'assumes local dir C:\\test is mapped as test for your server,
'so a local path like 
'C:\\test\\dir\\file.txt
'translates to a URL like
'http://server/test/dir/file.txt
tbPath = "C:\\Program Files\\The Bat!\\thebat.exe"
tbAcc = "ACCOUNT" 'replace with the name of an existing account
'----------------------------------------------
template = myDir & "\\template.tpl"
tmpTemplate = myDir & "\\tmp.tpl"
Set wshShell = WScript.CreateObject ("WSCript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
For each file in fso.GetFolder(myDir).Files 
   if right(file,4) = ".txt" then
      fname = fso.GetFileName(file)                           'file name, no path
      rec = left(fname, instr(1, fname, "~") -1 )    'recipient
      user = left(rec, instr(1, rec, "@") -1 )         'username
      'msgbox rec
      newDir = myDir & "\\" & rec
      if not fso.folderExists(newDir) then fso.createFolder(newDir)
      newFile = newDir & "\\" & fname
      if fso.fileExists(newFile) then fso.deleteFile(newFile)
      fso.moveFile file, newFile
      url = baseUrl & rec & "/" & fname
      
      '--read main template
      tmp = fso.OpenTextFile(template,1).readAll
      '-- create temp. template -------
      tmp = replace(tmp, "<<_recipient_>>", rec)
      tmp = replace(tmp, "<<_url_>>", url)
      tmp = replace(tmp, "<<_user_>>", user)
      Set a = fso.CreateTextFile(tmpTemplate, True)
      a.WriteLine(tmp)
      a.Close
      'send command to theBat, to create a message based on tmpTemplate 
      myCMD = "/MAILU=" & tbAcc & ";T=" & chr(34) & tmpTemplate & chr(34) & ";QUEUE"
      wshShell.run chr(34) & tbPath & chr(34) & " " & myCMD
      WScript.Sleep(2000) 'ensure command is executed, sleep 2 seconds
   end if
Next
'now messages are queued in Outbox, un-comment line below for sending
'wshShell.run chr(34) & tbPath & chr(34) & " /SENDALL"
Set fso = Nothing
Set wshShell = Nothing



and here is the template file template.tpl, save it in
myDir folder(as defined above)
Code
Hi <<_user_>>,
here is your file
<<_url_>>
Regards,
yournamehere
%TO="<<_recipient_>>"
%SUBJECT="test"


it should be easy to customize it to do what you need
 
Thank you for your help.

I tried this but it didn't work for me.
I may have the path incorrect.
 
replace C:\test in my example with C:\BAT\TA

put the file template.tpl in C:\BAT\TA

Then it should work, I tested it.
I use many such files to automate theBat(and other apps too) and they all work fine.
Pages: 1