Attach all files within a directory

Hi,

I have a Lotus script that detaches all atachments on a document to a directory on the C:\ Drive.

Sub Click(Source As Button)

 '-- Get Front and Backend Document

Dim ws As New NotesUIWorkspace



Dim uidoc As NotesUIDocument

Set uidoc = ws.currentdocument



Dim doc As NotesDocument

Set doc = UIDoc.document  



 '-- Create Session object to access Notes.ini "Directory" value

Dim Session As New NotesSession

Dim dirpath As String     

dirpath = session.GetEnvironmentString( "Directory", True )



 '-- Loop through all attachments in document and detach to Notes Data Directory

Dim rtitem As Variant     

Set rtitem = doc.GetFirstItem( "Body" )



 '-- if array of embedded objects exist then detach all attachments into the Notes Data directory

If Isarray( rtitem.EmbeddedObjects ) Then

	Forall o In rtitem.EmbeddedObjects

		If ( o.Type = EMBED_ATTACHMENT ) Then

			fullpath$ = dirpath + "\Quality\" + o.source

			Messagebox(fullpath$)

			Call o.ExtractFile( fullpath$ )

		End If

	End Forall

End If

Messagebox(fullpath$)

End Sub

Is there anyway I can have a button to do the reverse? Attach all files within a directory & remove the files from the directory after they have been attached ?

Thanks in advance for your help.

Neil

Subject: Sure…

Sub Click(Source As Button) '-- Get Front and Backend Document

Dim ws As New NotesUIWorkspace



Dim uidoc As NotesUIDocument

Set uidoc = ws.currentdocument

'-- Document can not be in edit mode

uidoc.EditMode = False



Dim doc As NotesDocument

Set doc = UIDoc.document  



 '-- Create Session object to access Notes.ini "Directory" value

Dim Session As New NotesSession

Dim dirpath As String, fileName As String

dirpath = session.GetEnvironmentString( "Directory", True ) + "\Quality\*.*"



 '-- Loop through all filenames in QUALITY subdir of NDD

fileName = Dir$(dirpath, 0)

Dim rtitem As NotesRichTextItem, object As NotesEmbeddedObject

Set rtitem = doc.GetFirstItem( "Body" )

Do While fileName <> ""

	Set object = rtitem.EmbedObject(EMBED_ATTACHMENT, "", fileName)

	fileName = Dir$()

Loop

Call doc.Save(True, True)

Call uidoc.Close

End Sub