Urgent svp open file

Résolu
sofianvb Messages postés 1 Date d'inscription mercredi 17 novembre 2004 Statut Membre Dernière intervention 17 novembre 2004 - 17 nov. 2004 à 22:24
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 - 17 nov. 2004 à 23:06
bjr tt le mde
je cherche quelqu'un qui peux m'aider à resoudre mon probleme:
je voudrai creer un programme qui va chercher dans un repertoire tous les fichiers *.txt de 1 à n en suite copier le contenu de ces fichiers et le mettre sur un seul fichier cummul.txt

1 réponse

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
17 nov. 2004 à 23:06
Option Explicit

Rem un CommandButton --> CmdCopy
Rem un ListBox  ----> Liste

Private Sub CmdCopy_Click()
    Call Lire("C:\...\...")
    Call Ecrire("C:\...\cummul.txt")
End Sub

Private Sub Lire(path As String)
    Dim nom As String
    If Right$(path, 1) <> "" Then path = path & ""
    nom = Dir(path & "*.txt")
    Do While nom <> vbNullString
' attention de ne pas copier cummul sur lui même
         if nom <> "cummul.txt" then 
         Liste.AddItem path & nom
         end if
         nom = Dir()
         Loop
End Sub

Private Sub Ecrire(nom As String)
    Dim zone As String
    Dim i   As Integer
    Open nom For Output As #1
    For i = 0 To Liste.ListCount - 1
        Open Liste.List(i) For Input As #2
             While Not EOF(2)
               Line Input #2, zone
               Print #1, zone
               Wend
             Close #2
        Next
    Close #1
End Sub
3
Rejoignez-nous