Skip Navigation Links



VBScript to find Fileage and send an e-mail

Author : Babu Dhinakaran S      Blog :Linuxos4all      Date: 11/7/2011 12:37:00 PM


'On Error Resume Next

Const ForReading = 1
today = now()

Set objMessage = CreateObject("CDO.Message")
objMessage.From = "babu.dhinakaran@jda.com"
objMessage.To = "babu.dhinakaran@jda.com"



Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile = objFSO.OpenTextFile("c:\filelist.txt", ForReading)

Do Until objTextFile.AtEndOfStream

folderspec = objTextFile.Readline
'Wscript.Echo "File in the Folder:" & folderspec
objMessage.Subject = folderspec
Agecount = 0


Set folder = objFSO.GetFolder(folderspec)
Set fc = folder.Files

For Each f1 in fc
file = f1.name
filespec = folderspec & file

Set file = objFSO.GetFile(filespec)

ShowDateCreated = file.DateCreated
'Wscript.Echo "FileName: " & filespec
'Wscript.Echo "ShowDateCreated:" & ShowDateCreated
difference = DateDiff("n",ShowDateCreated,today)

If difference > 30 Then
Agecount = Agecount + 1
End If
'Wscript.Echo "File Age in minutes is:" & difference
Next

'Wscript.Echo "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount

'mailbody = "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount
'objMessage.TextBody = mailbody

'Wscript.Echo "-----------------------------------------------"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "indiamailrelay.jda.corp.local"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

If Agecount > 0 Then

mailbody = "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount
objMessage.TextBody = mailbody
objMessage.Send
'Wscript.Echo "Total file older than 30 minutes at: " & folderspec & " are:" & Agecount

End If


Loop

------------------------------------------------------------------------------------

The above code basically, check for a fileage > 30 minutes and send an email if it is true.

It uses a text file as a input to read folder path where files exists
eg:- c:\temp\
Note: Make sure to provide full path as said above, if provided c:\temp this will generate an error.

Bloggers

active bloggers in the last 24 hrs. Number shown in the bracket represents number of posts published in past 24 hrs,


other authors(64)

Vashi Chandiramani(9)

sankarshan(7)

Kartik Ramaswamy(4)

MUNZ TDT(4)

Abhay Naxalrevolution(2)

AS(2)

Deepak(2)

Firoze Shakir Photographerno1(2)

Gaurav B Gothi(2)

Govind Kumar(2)

pixie(2)

Sanjeev(2)

Srinivasan Sampathkumar(2)

Tinkoo(2)

--- :) ----(1)

Abhishek Mukherjee(1)

aburman(1)

amarllyis(1)

Animesh Ganguly(1)

anisnest(1)

Anubhav Sharma(1)

Aravind GJ(1)

Archana Kumar(1)

arkadev(1)

Aruna Manikandan(1)

aseemrastogi2(1)

astrosunilnomy(1)

Atanu Ghosal(1)

Bharat(1)

Bharathram Pattabiraman(1)

bhuji(1)

BUTTERFLIES OF TIME(1)

churumuri(1)

cresloga(1)

Curry Leaf(1)

Deeps(1)

Dew(1)

Dhaval Mehta(1)

Dheeraj Pandey(1)

Dr Babu(1)

Erin W.(1)

Fidarose Isha(1)

Gandharv(1)

Garfield Dsouza(1)

Gv Sparx(1)

Harimohan(1)

Heartcrossings(1)

Hemu(1)

HRoi Consulting(1)

Ibrahim(1)

Indrani(1)

inquisitiveguurl(1)

Iti(1)

Javin Paul(1)

Kalyan P(1)

Kamal Sharma(1)

karanbhujbal(1)

Kichu Khonn(1)

Lakshmi Prabhala(1)

lijindev keloth(1)

M D(1)

mad madrasi(1)

magiceye(1)

mahima(1)

Manas Khatri Mastana(1)

Mayank Mishra(1)

mervin anto(1)

monikamanchanda(1)

Mridul Greenwold(1)

Nanka(1)

Neelam Dadhwal(1)

Nik P(1)

Nikhil Sheth(1)

nina a.(1)

nitya(1)

Nivedita Thadani(1)

parth joshi(1)

Prahallad Panda(1)

Prakash Jain(1)

Priya(1)

Pushkaraj Shirke(1)

R.D. Bhalekar(1)

Raji(1)

Ram Shiv Murti Yadav(1)

Ram Surjit(1)

Renu(1)

RNA Corp(1)

S Vijaya Saradha(1)

Sakshi Garg(1)

Sameena Prathap(1)

Santosh bs(1)

Shobha(1)

Shreya(1)

Shriti(1)

SJ(1)

Sorcerer(1)

Spiritual Sherpa(1)

Srikanth(1)

Sriram Khé(1)

Tanushree(1)

Tarang Sinha(1)

udaya chandran(1)

Ugich Konitari(1)

Vasudev Ram(1)

Vidya lakshmi(1)

Vikram Karve(1)

yashika G(1)

Yashodhara(1)

Yogesh(1)

yogesh singh(1)


garland of Languages of India
an amalgamation of the diversified traditions
gracefully presented with novelty
http://www.haaram.com