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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List of Documents divided by codes and emailed to those directors. 1

Status
Not open for further replies.

Tiahuana

Programmer
Oct 5, 2010
10
US
OK, I have a direcotry of documents, that list like this
600_20101122.csv

"Dim ctr,arrDocList, i
ctr = 0
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("\\Directory\FileList.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrDocList = Split(strNextLine , "_")
For Each i In arrDocList
Set objMessage = CreateObject("CDO.Mesessage") objMessage.Configuration.Fields.Item (" = 2
objMessage.Configuration.Fields.Item (" = "mail.whatever.org"
objMessage.Configuration.Fields.Item (" = 25

objMessage.Subject = "Email Motification For Late Charges"
objMessage.From = "whomever@wheverever.org"
objMessage.To = & arrDocList (0) &"@whereever.org"
objMessage.TextBody = "Message"
objMessage.AddAttachment "\\directory\" & arrDocList(0) & "_" & LogStamp() &".csv"

objMessage.Configuration.Fields.Update
objMessage.Send

Next
Loop"

I need to read a directory, where the 111_20101122.csv, and other similiar files exist. Attach these files one by one to e-mails and use the first part of the document name to reference the e-mail address. Exp. 111 is Whomever@whereever.org 222 is misseswhatever@wherever.org.

any help would be appreciated.
 
Set dicMapping = CreateObject("Scripting.Dictionary")
dicMapping.Add "111", "whomever@whereever.org"
dicMapping.Add "222", "misseswhatever@whereever.org"
If FSO.FolderExists("\\server\share\folder") Then
Set objFolder = FSO.GetFolder("\\server\share\folder")
For Each aFile In objFolder.Files
Wscript.Echo aFile.Name
strStart = Left(aFile.Name, InStr(aFile.Name, "_"))
Wscript.Echo strStart
If dicMapping.Exists(strStart) Then
Wscript.Echo "found in hashtable"
Wscript.Echo "target email = " & dicMapping.Item(strStart)
Call SendEmail(dicMapping.Item(strStart), aFile)
Else
Wscript.Echo "not found in hashtable"
End If
Next
Set objFolder = Nothing
End If
Set dicMapping = Nothing









I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
I figured it out Wednesday, thanks for replying we approached it the same way only I decided at the end to make a "Master.txt" document to easily adjust the e-mail addresses later. Thanks again, here's what I'm using.

"Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("list of all codes and the corresponding e-mail addresses.txt", ForReading)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrRevCode = Split(strNextLine , " ")

strFile = "files that I created in a previous step, I'm loading into an array "exp 111_20101129"\" & arrRevCode(0) &"_"& LogStamp & ".csv"
If objFSO.FileExists(strFile) Then

Set objMessage = CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item (" =
objMessage.Configuration.Fields.Item (" = "company e-mail location"
objMessage.Configuration.Fields.Item (" =
objMessage.Subject = "Email Notification For Late Charges"
objMessage.From = "e-mail address"

objMessage.TextBody = "Body Text"
objMessage.AddAttachment "strFile Directory" & arrRevCode(0) &"_"& LogStamp & ".csv"

'Wscript.Echo "RevCode: " & arrRevCode(0)
For i = 1 to Ubound(arrRevCode)
objMessage.To = ""& arrRevCode(i)
objMessage.Configuration.Fields.Update
objMessage.Send
' Wscript.Echo "E-mail Address: " & arrRevCode(i)
Next

End If
'I use this to move the documents that have been e-mailed above.
strFile2 = "same directory that I"m reading from\" & arrRevCode(0) &"_"& LogStamp & ".csv"
strDest="archived file\"& LogStamp & "\"
Set FSO=CreateObject("Scripting.FileSystemObject")
FSO.MoveFile strFile2,strDest
Loop
 
thanks for the star Tiahuana, it is not clear to me where your looping through arrRevCode corresponds with your looping as you read the contents of your emailaddress.txt
This is one of the advantages of dictionary objects, the .Exists is typically faster than the looping through an array

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
I forgot I changed it a little bit from my original description.

I created a masterlist.txt document of all codes and the corresponding supervisors e-mails addresses. I read this document instead, then search for the .csv document that matches. I thought this would be easier to maintain with turnover and such.

I simply read this document splitting the code and the e-mail address at the " "
111 name@email.com
112 name@email.com

After each one is added to the arrRevCode array, I look for the document that corresponds to that code here:
"strFile = "files that I created in a previous step, I'm loading into an array "exp 111_20101129"\" & arrRevCode(0) &"_"& LogStamp & ".csv""

If I find the document that corresponds with the arrRevCode then I simple go the the e-mail part and attach the document and address the e-mail using the revCode and a previous function I setup "LogStamp"

If I take out the rest of the stuff I added with the e-mail here was the origianl array.

"Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrRevCode = Split(strNextLine , " ")


For i = 1 to Ubound(arrRevCode)
Wscript.Echo "E-mail Address: " & arrRevCode(i)
Next
Loop"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top