Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Help

Status
Not open for further replies.

jpotucek

Technical User
Jan 26, 2005
144
US
I have this code that will basically read a filename, filesize and last update date and then email the results (scheduled on a daily basis)

Dim fso, f1, f2
'Set the file attrribute to append
Const ForWriting = 8
Set fso = CreateObject("Scripting.FileSystemObject")

' Get a File object to query.
set f1 = fso.GetFile("\\stm-adm2\schematic\uploads\Versus.20071203.csv")
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "db_montor_srvr@stm-adm2.olntv.com"
objEmail.To = "jrichardson@versus.com"
objEmail.Subject = "IT Operations Status Report - AFF web site File Compare"
objEmail.Textbody = f1.name & " " & f1.Size & " " & f1.DateLastModified & " "
'& vbcrlf & vbcrlf & _
'== remote smtp configuration

objEmail.Configuration.Fields.Item _
(" = 2
'Name or IP of Remote SMTP Server
objEmail.Configuration.Fields.Item _
(" = "192.168.0.50"
'Server port (typically 25)
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objEmail.Send



This code works fine but my problem is that the Filename that I am reporting on changes everyday!!!! Today the filename is filename.20071203.csv
and tomorrow it will be filename.20071204.csv and so on....

How can I report on this file is the name changes everyday???

Thinking that I could use a wildcard character for the filename but that didn't work...
Can I change my code to simple look at the contents on the directory where the file lives and report on the contents? if so how??

any help would be much appreciaTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Replace this:
set f1 = fso.GetFile("\\stm-adm2\schematic\uploads\Versus.20071203.csv")
with this:
Set f2 = fso.GetFolder("\\stm-adm2\schematic\uploads")
For Each f1 In f2.Files

And this:
objEmail.Send
with this:
objEmail.Send
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If past days files remain in the directory and you only want the file from TODAY then use the following:

Code:
MyDate = Year(Date) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) 
Set f1 = fso.GetFile("\\stm-adm2\schematic\uploads\Versus." & MyDate & ".csv")

Note that in the above I am assuming both month and day will always have a leading zero if the month or day is less than 10 since you show an 03 in your example.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top