When a new file is found, email it

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

When a new file is found, email it

Post by Marcus Tettmar » Wed Sep 20, 2006 1:27 pm

This script will continuously watch a folder and when it finds a new file in that folder it will send it by email. Modify the paths and email parameters at the start of the script. This version loops continuously. If you prefer, remove main loop and instead schedule to take place periodically/repetitively.

Code: Select all

//The incoming folder
Let>InFolder=d:\infiles
//Processed Log File
Let>ProcessedLog=d:\processed.log
//Sendmail vars
Let>server=mail.server.com
Let>[email protected]
Let>[email protected]
Let>fromname=Fred
Let>subject=New file for you
Let>body=New file for you

Label>mainloop

//Get a list of folders in InFolder
GetFileList>%InFolder%\*.*,file_list,;
Separate>file_list,;,files
//Loop through folder list
If>files_count>0
   Let>k=0
   Repeat>k
     Let>k=k+1
     Let>ThisFile=files_%k%
     //Does this one exist in processed.log
     Let>SendIt=TRUE
     IfFileExists>ProcessedLog
        ReadFile>ProcessedLog,ProcessedList
        Position>ThisFile,ProcessedList,1,p
        If>p>0
           //This file already processed
          Let>SendIt=FALSE
        Endif
     Endif
     //Ok to process this file
     If>SendIt=TRUE
        //Write to processed log
        WriteLn>ProcessedLog,r,ThisFile
        //Send the file
        SMTPSendMail>to,server,from,fromname,subject,body,ThisFile
     Endif
   Until>k=files_count
Endif

Wait>0.2
Goto>mainloop
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts