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 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| Option Explicit
Dim objFSO, objFile, tabTags, countLine, strLine, DeleteTag
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("my_tagged_file.txt", 1)
tabTags = array()
countLine = 1
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
RegEx_SearchTag strLine, "(<[A-Za-z0-9_]*>)" ' Recherche balise d'ouverture
RegEx_SearchTag strLine, "(</[A-Za-z0-9_]*>)" ' Recherche balise de fermeture
' WScript.Echo "Ligne en cours : " & countLine & VbCrLf & VbCrLf & ListTags
countLine = countLine + 1
Loop
WScript.Echo "Balise(s) orpheline(s) :" & VbCrLf & VbCrLf & ListTags
' On ferme le fichier et on libère l'objet
objFile.Close
Set objFile = Nothing
' ******** Fonctions ********
Function RegEx_SearchTag(strLine, strPattern)
Dim objRegEx, colMatches, objMatch, TempOpeningTag
Set objRegEx = New RegExp
objRegEx.Pattern = strPattern
objRegEx.IgnoreCase = True
objRegEx.Global = True
Set colMatches = objRegEx.Execute(strLine)
For Each objMatch In colMatches
If Mid(objMatch.Value, 2, 1) = "/" Then ' Balise de fermeture
TempOpeningTag = Replace(objMatch.Value, "/", "")
RemoveTag tabTags, TempOpeningTag
If DeleteTag <> TempOpeningTag Then ' Si pas de balise d'ouverture correspondant
AddTag tabTags, objMatch.Value & ";" & countLine
End If
Else ' Balise d'ouverture
AddTag tabTags, objMatch.Value & ";" & countLine
End If
Next
Set objRegEX = Nothing
End Function
Function RemoveTag(tabTags, strTag) ' Suppression d'une balise en memoire
Const DeleteIndicator = "DELETEME"
Dim i, tabItem
DeleteTag = ""
For i = 0 to UBound(tabTags)
tabItem = Split(tabTags(i), ";")
If tabItem(0) = strTag Then
tabTags(i) = DeleteIndicator
DeleteTag = strTag
' Exit For
End If
Next
tabTags = Filter(tabTags, DeleteIndicator, False, 1)
End Function
Function AddTag(tabTags, strTag) ' Ajout d'une balise en memoire
ReDim Preserve tabTags(UBound(tabTags) + 1)
tabTags(UBound(tabTags)) = strTag
End function
Function ListTags ' Liste des balises en memoire
Dim InfoTag, i, tabItem
InfoTag = "Nom balise" & VbTab & "Ligne" & VbCrLf & VbCrLf
For i = 0 to UBound(tabTags)
tabItem = Split(tabTags(i), ";")
InfoTag = InfoTag & tabItem(0) & VbTab & tabItem(1) & VbCrLf
Next
If UBound(tabTags) = -1 Then
ListTags = "Aucun probleme d'integrite"
Else
ListTags = InfoTag
End If
InfoTag = ""
End Function |
Partager