Announcement

Collapse
No announcement yet.

Searching for file in folder named as current month using vbs script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Searching for file in folder named as current month using vbs script

    Hi, all!!
    I need some help with vbs script. We have production environment where log file is updated each day in folder named as current month.
    (\\server\year\current month).
    For example: \\London\2010\june\LogFile.cvs

    I created script that can take log file from the current folder (June for now) and email it to few recipients. Here is the script code:

    Code:
    Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Orion Heater Tracking file" objMessage.From = "[email protected]" objMessage.To = "[email protected], [email protected]" objMessage.TextBody = "Orion Heater Tracking file attached to this e-mail message." objMessage.AddAttachment "\\London\2010\june\LogFile.cvs"
    objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"
    objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objMessage.Configuration.Fields.Update objMessage.Send
    WScript.Echo "The email message has been sent!!"
    The main problem is: next month the log file will be in folder named July ( \\London\2010\July\LogFile.cvs) and the path in the script will need to be changed accordingly... It is possible to use some variable based on current month to tell the script where look for the log file to avoid situation when user will need change path in the script each month manually?

  • #2
    Re: Searching for file in folder named as current month using vbs script

    If the OS language is English, you'll get the name of the Month equally as the name of the folder with the code below.

    Code:
    dt = date()
    strMonth = MonthName(Month(dt), false)
    yyyy = Year(dt)
    
    objMessage.AddAttachment _
       "\\London\" & yyyy & "\" & strMonth & "\LogFile.cvs"
    Date/Time Functions


    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Searching for file in folder named as current month using vbs script

      Thanks, Rems!! As always, it work!!!

      Comment

      Working...
      X