par _ledude_ » 10 Fév 2004 à 11:36
Ben en fait je viens de m'en sortir.Voici donc mon script final (merci oguruma pour la charnière centrale).A partir d'un répertoire racine, je récupère tous les fichiers contenus dans ce répertoire ainsi que dans ses sous répertoires.Pour chaque fichier trouvé, je crée un document le stockant. Le nom du sous répertoire me servant à catégoriser le document en question.Bien sûr c'est améliorable...Voici le synopsis de l'agentSynopsis de base de documents Lotus Notes - créé à 11:04:23 le 10/02/2004Informations d'agentNom : Import des objets externesDernière modification : 10/02/2004 11:01:59Commentaire : [Sans]Agent partagé : OuiType : LotusScriptEtat : Activé(e)Déclencher : Lorsque vous le sélectionnez dans le menu Actions.S'applique à : Exécuter une fois (commandes @ autorisées)Code LotusScript :Option PublicOption DeclareSub Initialize Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim db As NotesDataBase Dim result As Variant Dim fn As Variant Dim Rep As String Dim pos As Integer On Error Goto GestErr Set db = session.CurrentDataBase 'Récupération du répertoire racine fn = ws.SaveFileDialog( True, "Répertoire racine", "" ) Forall file In fn Rep = file End Forall 'On scanne le répertoire source result = scanDirectory(Rep,"*.*", db) Exit Sub GestErr: Messagebox "Base : " & db.Title & " - Agent <Import des objets externes> - Procédure <Initialize> : Erreur " & Cstr(Err) & " " & Error$ & " à la ligne " & Cstr(Erl) Exit Sub End SubFunction scanDirectory( path As String, mask As String, db As NotesDataBase) As Integer'On navigue à travers le répertoire donné pour récupérer tous les sous dossiers ainsi que les fichiers'Pour chaque sous dossier trouvé, on exécute à nouveau la fonction'Pour chaque fichier trouvé, on crée un document qui stocke le dit fichier Dim listDir() As String Dim nbDir As Integer Dim fileName As String Dim dirName As String Dim attrib As Integer Dim pathName As String Dim newPathName As String Dim ok As Integer Dim n As Integer On Error Goto handleError nbDir=0 Redim listDir(0) pathname=path+"\"+mask dirName = Dir$(pathname,16) '// on recherche en premier les répertoires Do While dirName <> "" If dirname<>"." And dirname<>".." Then attrib = Getfileattr(path+"\"+dirName) If attrib=16 Then newpathName=path+"\"+dirName listDir(nbDir)=newPathName nbDir=Nbdir+1 Redim Preserve listDir(nbDir) Print "Directory : ";dirname End If End If dirName = Dir$() Loop '// Maintenant on analyse les fichiers du repertoire fileName = Dir$(pathname,6) Do While fileName <> "" Print pathname+"\"+fileName'On crée un document qui stocke le fichier trouvé Call creeDoc(path, fileName, db) fileName = Dir$() Loop '// on analyse les directory détectées For n=0 To Ubound(listDir) -1 ok=scanDirectory( listDir(n), mask, db) Next scanDirectory=True Exit Function handleError: Messagebox "Base : " & db.Title & " - Agent <Import des objets externes> - Fonction <scanDirectory> : Erreur n ° " & Err & " - " & Error$ & " ligne " & Erl,16,"Scan Directory" Resume fin fin: scanDirectory=False End FunctionFunction creeDoc(NomRep As String, NomFich As String, db As NotesDataBase)'Création d'un document stockant le fichier trouvé'Le nom du répertoire contenant ce fichier est utilisé comme catégorie'Le nom du fichier comme titre de document Dim doc As NotesDocument Dim strNomElement As String Dim Rep As String strNomElement = Strleftback(NomFich, ".") Rep = Strrightback(NomRep, "\") 'Création du document stockant l'élément externe Set doc = New NotesDocument(db) doc.Form = "m_theme" doc.SubJect = Format(Now(), "dd/mm/yyyy") & " - " & strNomElement doc.Categories = Remplace(Rep, "=", ":") doc.SubCat = "10 - Fichier Externe" doc.LastCat = "- Aucune -" doc.d_coauteurs = "MrX" 'Attachement de l'élément externe Dim rtitem As Variant Dim object As NotesEmbeddedObject Set rtitem = New NotesRichTextItem ( doc, "Body" ) Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", NomRep & "\" & NomFich) Call doc.ComputeWithForm(True,False) Call doc.Save(True,False) Exit FunctionGestErr: Messagebox "Base : " & db.Title & " - Agent <Import des objets externes> - Fonction <CreeDoc> : Erreur " & Cstr(Err) & " " & Error$ & " à la ligne " & Cstr(Erl) Exit FunctionEnd FunctionFunction Remplace(strEntree As String, car1 As String, car2 As String) As String Dim strChaine As String Dim intCar As Integer strChaine = strEntree While Not Instr(strChaine , car1) = 0 intCar = Instr(strChaine , car1) strChaine = Mid(strChaine, 1, intCar-1) & car2 & Mid(strChaine, intCar+Len(car1)) Wend Remplace = strChaineEnd Function OOUUFFFFFFFF, voilà une bonne chose de faite......Dude