Attachment file extraction to file server directory

Hi all,

I need to do a file extraction of attachments that reside in documents in a specific view and need to verify if the document already exists in the target directory to avoid writing duplicates and possibly save time on agent execution. The view that the agent will run on has more than 450K documents with attachments in each.

I have gone through this entire forum and also through the Lotus Notes Help on the subject and there is very little if understandable information on the topic (ie. The ‘Dir’ function). This is whjat LN Help gives as an example code:

’ List the contents of the c:\ directory, one entry per line.

Dim pathName As String, fileName As String

pathName$ = “c:*.*”

fileName$ = Dir$(pathName$, 0)

Do While fileName$ <> “”

Print fileName$

fileName$ = Dir$()

Loop

Has anyone done anything like this before? Is there some sample code available somewhere? Any assistance would help me tremendously.

Many thanks,

Jean

Subject: Well, yes I’ve done something similar

in my case, the database was a mail-in that accepted memos with attachments from external partners.

The agent I wrote processed each incoming memo

determined who had sent the file

mapped that to a directory

checked that no file of same name existed

if allowed detached the file into the correct directory

if not flagged it for manually processing

Therefore In my honest opinion its defintely possible to do what you want.

So how to do it?

My code is long gone, but I can give you some pointers

Once you have decided which directory you want to detach into you will need two things

a) a file name - I suggest you use the name of the attachment

b) a means of checking for teh presence of the file

and what you missed about DIR$ is in the middle of the help where you got your sample

“To determine whether a particular file exists, use an exact file name for the file_spec argument to Dir or Dir$. The return value is either the file name or, if the file does not exist, the empty string (”“).”

That means you can write a function something like this

(pointers only ; this code has not been compiled or tested)

REM Run this against a selected document that has Body field

Function DetachToDir( doc as NotesDocument, dirpath as string) as boolean

DetachToDir = False

If doc.HasEmbedded Then

Set body = doc.GetFirstItem("Body")



REM Get attachments

Forall att In body.EmbeddedObjects

   If att.Type = EMBED_ATTACHMENT Then

        filepath$ = dirpath & "\\" & att.Source

        if dir$( filepath) then

           Call att.ExtractFile(filepath$)

           DetachToDirectory = True

        end if 



   End If

end forall

end if

End Function

So now all you have to do is write the code to use it :=}

Note: if you want this to happen automatically - e.g. by a schedule agent - you need to ensure that he SERVER has access to the relevant directories

(In my case at first it was a drive on the same server

or later a mapped drive on a separate file server)

Good luck - and let us know how you get on

Subject: RE: Well, yes I’ve done something similar

Hi Alan,

Thanks for yor great help. Much appreciated. I will try this later this afternoon. I guess you’ll read this tomorrow.

Cheers mate,

Jean

Subject: RE: Well, yes I’ve done something similar

Hi Alan,do you remember how you called your function? I have a hidden view from which this agent will work. I suppose we’re talking about a doc collection but how to call the function eludes me.

Jean