Would some one help me looking at the script

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Would some one help me looking at the script

Post by timle » Thu Mar 29, 2007 10:52 pm

I run this script to send email with the file name when the file come in to the system, but it did not give me the file name


=========================
//The incoming folder
Let>InFolder=W:\\HOTFOLDERS\Rumbo\success\
//Processed Log File
Let>ProcessedLog=W:\\HOTFOLDERS\Rumbo\success\processed.log
//Sendmail vars
GetDate>date
GetTime>time
Let>server=mailhost.chron.com
Let>to=[email protected]
//[email protected];
Let>from=[email protected]
Let>fromname=New Rumbo File
Let>subject=There is new Rumbo file!
Let>body=System has just processed a Rumbo page at %time% on %date% %CRLF%The name of the file is %files%.%CRLF%%CRLF%Thank 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,Attachments
Endif
Until>k=files_count
Endif

//Wait>0.2
//Goto>mainloop

==========================

I got this email in the body:
"System has just processed a Rumbo page at 5:41:12 PM on 3/29/2007 The name of the file is %files%."

How can I make the %files% display the file name

thank you

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Mar 29, 2007 11:39 pm

Move the Let>body= line to after the Separate> line where you define files.

When you are creating %body% now, there is no value for %files% yet.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Mar 30, 2007 12:32 am

Program flow is an issue, but the other problem is that "files" is an array if it is assigned with

GetFileList>%InFolder%\*.*,file_list,;
Separate>file_list,;,files

so %files% doesn't work, it has to be %files_n%.

Or maybe you meant to use %ThisFile%?

I also see the mail send command includes attachments, but there's no associated definition.

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

I did both of the suggestions, but it still did not work

Post by timle » Fri Mar 30, 2007 3:19 pm

This is what I got:

System has just processed a Rumbo page at 10:12:39 AM on 3/30/2007 The name of the file is %ThisFile%.

Thank you
============================================
and this is the scripts

//The incoming folder
Let>InFolder=W:\\HOTFOLDERS\Rumbo\success\
//Processed Log File
Let>ProcessedLog=W:\\HOTFOLDERS\Rumbo\success\processed.log
//Sendmail vars
GetDate>date
GetTime>time
Let>server=mailhost.chron.com
Let>to=[email protected]
//[email protected];
Let>from=[email protected]
Let>fromname=New Rumbo File
Let>subject=There is new Rumbo file!

//Label>mainloop

//Get a list of folders in InFolder
GetFileList>%InFolder%\*.*,file_list,;
Separate>file_list,;,files
Let>body=System has just processed a Rumbo page at %time% on %date% %CRLF%The name of the file is %ThisFile%.%CRLF%%CRLF%Thank you

//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,
Endif
Until>k=files_count
Endif

//Wait>0.2
//Goto>mainloop
DeleteFile>%InFolder%\*.*

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Mar 30, 2007 4:06 pm

Still need to move Let>Body line happen after defining %ThisFile%
Try moving it like this:

Code: Select all

//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%

Let>body=System has just processed a Rumbo page at %time% on %date% %CRLF%The name of the file is %ThisFile%.%CRLF%%CRLF%Thank you

//Does this one exist in processed.log 
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Very close to accomplish the task

Post by timle » Fri Mar 30, 2007 4:55 pm

I have made the change to the script to make it simpler, and I got this email:

System has just processed a Rumbo page at 11:47:46 AM on 3/30/2007
The name of the file is W:\\HOTFOLDERS\Rumbo\success\0330rumboHp02 copy.PDF.


How can I just display the name of the file "0330rumboHP02 copy.pdf" not the whole path

thank you
=========================================
here is the script

//The incoming folder
//Let>InFolder=W:\\HOTFOLDERS\Rumbo\success\
//Processed Log File
//Let>ProcessedLog=W:\\HOTFOLDERS\Rumbo\success\processed.log
//Sendmail vars
GetDate>date
GetTime>time
Let>server=mailhost.chron.com
Let>to=[email protected]
//[email protected];
Let>from=[email protected]
Let>fromname=New Rumbo File
Let>subject=There is new Rumbo file!


GetFileList>W:\\HOTFOLDERS\Rumbo\success\*.*,files

Let>body=System has just processed a Rumbo page at %time% on %date% %CRLF%The name of the file is %files%.%CRLF%%CRLF%Thank you


//Send the file
SMTPSendMail>to,server,from,fromname,subject,body,
DeleteFile>%InFolder%\*.*

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Mar 30, 2007 8:52 pm

Assuming the directory tree structure is known, you can use Separate> to grab just the part after the last "\", something like this test:

let>filename=W:\\HOTFOLDERS\Rumbo\success\0330rumboHp02opy.PDF
Separate>filename,\,myfile
messagemodal>%myfile_6%

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Mar 30, 2007 9:01 pm

Why did you change the section that was woking before?
I think that all you had to do was to move the one line that defined %Body%

Use the files_n for the value of %ThisFile%.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Mar 31, 2007 2:10 am

Hmmm, just a thought, is it possible there could be more than one file returned by

GetFileList>W:\\HOTFOLDERS\Rumbo\success\*.*,files

?

If so then "files" will contain a list of files and the email will be a mess.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Mar 31, 2007 7:12 pm

That is why using Separate was included, it will pull out the individual file names.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Thank you both for yourhelp.

Post by timle » Thu Apr 19, 2007 3:13 pm

Thank you for your help it works great. I am just a bad coder

Also I want to omid the extention in the file name FILExxx.PDF
I just want to display FILEXXX, not the pdf part.

The MidStr function is >string,start,length,result
Is there any function to >string,end,length,result?

thanks

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Apr 19, 2007 4:16 pm

You can do that by finding the length of the string and then calculating how many characters you want from the start, like:

Let>filename=myfile.txt
Len>filename,lfile
Let>lfile=lfile-4
MidStr>filename,1,lfile,nufile
MDL>%nufile%

But in this case it is easier to use Separate> again to split the filename at the period:

Let>filename=myfile.txt
Separate>filename,.,pce
MDL>%pce_1%

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Thu Apr 19, 2007 4:44 pm

Yes but the file names are not constant but the file extention is, so it's easier to count from the last character instead of the first character

timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

Post by timle » Thu Apr 19, 2007 5:01 pm

:?

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

Post by Marcus Tettmar » Thu Apr 19, 2007 5:53 pm

Doesn't matter how long the filename or the extension is - the following will find the position of the dot (period) between name and extension and extract everything up until the dot:

Let>filename=c:\dir\somefile.ext
Position>.,filename,1,pdot
Let>pdot=pdot-1
MidStr>filename,1,pdot,filename
MessageModal>filename
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
Sign up to our newsletter for free automation tips, tricks & discounts