xtfab
Messages postés3Date d'inscriptionmercredi 14 mai 2003StatutMembreDernière intervention24 juin 2003
-
24 juin 2003 à 12:46
cs_rene38
Messages postés1858Date d'inscriptionsamedi 29 juin 2002StatutMembreDernière intervention17 octobre 2013
-
24 juin 2003 à 14:51
Bonjour à tous,
Je souhaiterai savoir comment faire pour ajouter un fichier texte à la suite d'un autre. J'ai essayé plusieurs méthodes (append...) trouvées dans les sources sans succès.
Si vous savez comment faire, n'hésitez pas !
cs_sebV
Messages postés107Date d'inscriptionmardi 20 août 2002StatutMembreDernière intervention15 octobre 2004 24 juin 2003 à 14:50
Ben tu ouvre en binaire, tu capte la taille tu fichier que tu mete dans une var, puis tu faite ecrit à cette emplacement (enfin si ta variable est en string) :
dim lngTaille as Long
dim strText as string
open "c:\fichier.txt" for binary as #1
lngTaille=LOF(1)
put #1,lngTaille,strText
Close #1
J'ai pas tester, si ça vien a couper le dernier caractère tu incrémente lngTaille de 1 avant d'écrire.
cs_rene38
Messages postés1858Date d'inscriptionsamedi 29 juin 2002StatutMembreDernière intervention17 octobre 201311 24 juin 2003 à 14:51
Bonjour
Avec Append, ça doit marcher :
Dim Ligne As String, nFich1 As Long, nFich2 As Long
nFich1 = FreeFile
Open "C:\Chemin1\Fichier1.txt" For Append As #nFich1
nFich2 = FreeFile
Open "C:\Chemin2\Fichier2.txt" For Input As #nFich2
Do While Not EOF(nFich2)
Line Input #nFich2, Ligne
Print #nFich1, Ligne
Loop
Close nFich1
Close nFich2
Fichier1 contiendra Fichier1 et Fichier2 à la suite.
Tu peux aussi créer un troisième fichier sans modifier les 2 :
Dim Ligne As String, nFich1 As Long, nFich2 As Long, nFich3 As Long
nFich3 = FreeFile
Open "C:\Chemin1\Fichier3.txt" For Output As #nFich3
nFich1 = FreeFile
Open "C:\Chemin1\Fichier1.txt" For Input As #nFich1
Do While Not EOF(nFich1)
Line Input #nFich1, Ligne
Print #nFich3, Ligne
Loop
Close nFich1
nFich2 = FreeFile
Open "C:\Chemin2\Fichier2.txt" For Input As #nFich2
Do While Not EOF(nFich2)
Line Input #nFich2, Ligne
Print #nFich3, Ligne
Loop
Close nFich2
Close nFich3
C'est Fichier3.txt qui contiendra Fichier1.txt et Fichier2.txt à la suite, Fichier1.txt et Fichier2.txt n'étant pas modifiés.