IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

comparer deux fichier .txt


Sujet :

VBScript

  1. #1
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut comparer deux fichier .txt
    Bonjour, j'ai un script qui compare deux fichiers.txt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    set WshShell = WScript.CreateObject("WScript.Shell") 
    DesktopPath = WSHShell.SpecialFolders("Desktop")
     
    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' On ouvre la boite de dialogue pour selectionner le fichier à comparer:
     
    set objDialog = CreateObject("SafrcFileDlg.FileOpen") 
    objDialog.OpenFileOpenDlg 
    vrFchSlctn = objDialog.FileName
    'wscript.echo objDialog.FileName 
    '''''''''''''''''''''''''''''''''''''''''''''''''
     
    '''''''''''''''''''''''''''''''''''''''''''''''''
    ' On copie le fichier 
     
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.CopyFile vrFchSlctn, "tempComparLignes.tmp"
    '''''''''''''''''''''''''''''''''''''''''''''''''
     
    Wscript.echo "On marque une pause le temps de modifier les paramétres manuellement dans votre application" & vbCrLf _
               & "Appuyez sur OK quand vous aurez fini"
     
     
     
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSourceFile = objFSO.OpenTextFile("tempComparLignes.tmp", 1) ' Fichier originale
    Set objSourceFile2 = objFSO.OpenTextFile(vrFchSlctn, 1) 'Fichier copié
     
    vrNumLigne = 0
     
    Do Until objSourceFile.AtEndOfStream Or objSourceFile2.AtEndOfStream
       vrNumLigne = vrNumLigne + 1
       vrLigne = objSourceFile.ReadLine
       vrLigne2 = objSourceFile2.ReadLine
     
       vrComprLign = StrComp(vrLigne, vrLigne2, 1)
     
          If nombre = 1 Or nombre = -1 Or IsNull(vrComprLign) then
                 vrNul = "Le fichier a été modifier"
                 vrLignDif = vrLignDif & vrNumLigne & ": " & vrLigne & vbCrLf & vrNumLigne & ": " & vrLigne2 & vbCrLf & vbCrLf
                 'vrLignDif2 = vrLignDif2 & "Origin " & vrNumLigne & ": " & vrLigne & vbCrLf & "Modif  " & vrNumLigne & ": " & vrLigne2 & vbCrLf & vbCrLf
          Else
          End If
     
    Loop
    objSourceFile.Close
    objSourceFile2.Close
     
     
    If IsEmpty(vrNul) Then
             Wscript.Echo "Le fichier n'a subi aucune modification"
    Else
             Wscript.Echo vrLignDif
              Const ForReading = 1, ForWriting = 2 
                Set FichierTXT = WScript.CreateObject("WScript.Shell") 
                 Dim fso, f 
                 Set fso = CreateObject("Scripting.FileSystemObject") 
                 Set f = fso.OpenTextFile(DesktopPath & "\Résulta de la comparaison du fichier.txt", ForWriting,true) 
                 f.writeline("Fichier source: " & vrFchSlctn) 
                 f.writeline("")
                 f.writeline("")  
                 f.writeline(vrLignDif) 
              f.close
    End If
     
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set fsoFile = fso.getFile("tempComparLignes.tmp")
     fsoFile.delete
    Mais si la ligne 5 du fichier 1 et pleine, et que la ligne 5 du fichier deux est vide, les script ne voi pas la différence, sauriez vous m'aider a aranger ca ?

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    et il y as combien de ligne dans tes 2 fichiers ..?

  3. #3
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    j'ai créer un fichier bidon pour le test:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    rdhdfgj
    fhdgfjgf
    cvjngfjgf
    vcnvcnvcn
    vcnvcnvcn
    ncvn vcnc
    vcnbvnvbn
    nvcnvcn
    Puis je l'ai modifier:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    rdhdbv,
    fhdgfjgf
    cvjnxgf
    vcnvcnvcn
     
    ncvn vcnc
    vcnbvnvbn
    nvcnvcn

  4. #4
    Membre habitué
    Inscrit en
    Novembre 2005
    Messages
    130
    Détails du profil
    Informations forums :
    Inscription : Novembre 2005
    Messages : 130
    Points : 166
    Points
    166
    Par défaut
    bonjour,

    en remplaçant nombre par vrComprLign cela donne ce code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    Dim objFSO As FileSystemObject
    Dim objSourceFile As TextStream
    Dim objSourceFile2 As TextStream
     
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSourceFile = objFSO.OpenTextFile("c:\test.txt", 1) ' Fichier originale
    Set objSourceFile2 = objFSO.OpenTextFile("c:\test2.txt", 1) 'Fichier copié
     
    vrNumLigne = 0
     
    Do Until objSourceFile.AtEndOfStream Or objSourceFile2.AtEndOfStream
       vrNumLigne = vrNumLigne + 1
       vrLigne = objSourceFile.ReadLine
       vrLigne2 = objSourceFile2.ReadLine
     
       vrComprLign = StrComp(vrLigne, vrLigne2, 1)
     
          If vrComprLign = 1 Or vrComprLign = -1 Or IsNull(vrComprLign) Then
                 vrNul = "Le fichier a été modifier"
                 vrLignDif = vrLignDif & vrNumLigne & ": " & vrLigne & vbCrLf & vrNumLigne & ": " & vrLigne2 & vbCrLf & vbCrLf
                 'vrLignDif2 = vrLignDif2 & "Origin " & vrNumLigne & ": " & vrLigne & vbCrLf & "Modif  " & vrNumLigne & ": " & vrLigne2 & vbCrLf & vbCrLf
          Else
          End If
     
    Loop
    objSourceFile.Close
    objSourceFile2.Close
     WScript.Echo vrLignDif
    et donne le resultat:

    1: rdhdfgj
    1: rdhdbv,

    3: cvjngfjgf
    3: cvjnxgf

    5: vcnvcnvcn
    5:

    donc tout va bien !
    tu me dis

  5. #5
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    merci beaucoup c'est parfait

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comparer deux fichier .xls
    Par oursquetaire dans le forum Excel
    Réponses: 6
    Dernier message: 06/07/2006, 16h52
  2. [JDOM] Comparer deux fichiers XML en Java
    Par calimero2611 dans le forum Format d'échange (XML, JSON...)
    Réponses: 5
    Dernier message: 30/06/2006, 11h19
  3. Comparer deux fichier
    Par Taz_8626 dans le forum Langage
    Réponses: 3
    Dernier message: 20/06/2006, 11h46
  4. comparer deux fichiers avec une api windows
    Par sweetdreamer dans le forum Windows
    Réponses: 4
    Dernier message: 25/05/2006, 22h10
  5. Fonction c qui compare deux fichiers ???
    Par babyface dans le forum C
    Réponses: 4
    Dernier message: 19/11/2005, 13h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo