option explicit Function OnInit(initData) initData.name = "Commande_SelectFileFromTxt" initData.desc = "Sélectionne des fichiers à partir d'un fichier texte." initData.min_version = "11.7" initData.version = "beta" initData.default_enable = true initData.config.FichierTxt = "temp.txt" initData.config.EffacerJournal = false initData.config_desc = Dopus.Create.Map("FichierTxt", "Entrer le nom du fichier texte qui liste les fichiers à sélectionner.", _ "EffacerJournal", "Effacer ou non le journal au lancement de la commande.") End Function Function OnAddCommands(addCmdData) Dim cmd: Set cmd = addCmdData.AddCommand() cmd.name = "SelectFromTxt" cmd.method = "OnSelectFromTxt" cmd.desc = "Sélectionne des fichiers à partir d'un fichier texte" cmd.label = "SelectFromTxt" cmd.icon = "reselect" End Function Function OnSelectFromTxt(funcData) Dim fs: Set fs = CreateObject("Scripting.FileSystemObject") Dim txtFilename: txtFilename = script.config.FichierTxt Dim strCurrentPath: strCurrentPath = funcData.func.sourcetab.path Dim i, numLines, strData, Line, CptVide ' Clear log If script.config.EffacerJournal = True Then Dopus.clearOutput ' Test if txt file exist On Error Resume Next Dim fn: Set fn = fs.OpenTextFile(strCurrentPath & "\" & txtFilename, 1, false) If err.number > 0 Then Dopus.OutputString "Erreur : Pas de fichier '" & txtFilename & "' dans le dossier source" : Exit Function ' Count lines number in file strData = fs.OpenTextFile(strCurrentPath & "\" & txtFilename, 1).ReadAll numLines = Split(strData, vbCrLf) Dopus.OutputString "Info : Il y a " & UBound(numLines) + 1 & " lignes dans le fichier '" & txtFilename & "'" 'Create array Dim objFiles: Set objFiles = DOpus.Create.Vector() If UBound(numLines) > 0 Then For i = LBound(numLines) to UBound(numLines) Line = Trim(numLines(i)) If Line <> "" Then If fs.FolderExists(strCurrentPath & "\" & Line) Or fs.FileExists(strCurrentPath & "\" & Line) Then objFiles.push_back = Line Else Dopus.OutputString "Erreur (ligne " & i + 1 & ") : L'élément '" & Line &"' n'existe pas dans le dossier source" End if Else Dopus.OutputString "Erreur (ligne " & i + 1 & ") : La ligne est vide" CptVide = CptVide + 1 End If Next End If 'Select files from array funcData.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH") Dopus.OutputString "Info : " & objFiles.count & " éléments sur " & UBound(numLines) + 1 - CptVide & " ont été sélectionnés" End Function