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
| Option Explicit
Const ForWriting = 2, ForReading = 1
Dim fso, objOut, objTemp, ContentFile, FinalText
Set fso = CreateObject("Scripting.FileSystemObject")
' Fichier listant tous ceux qui répondent au critère : extension = xsc
Set objOut = fso.OpenTextFile(".\Filelog.txt", ForWriting, True)
' Appel de la fonction de recherche :
Scan4Files "C:\"
' Avertit lorsque la recherche est terminée :
MsgBox "Recherche terminée", vbSystemModal
'===========================
Sub Scan4Files(sFolder)
'Fonction de recherche et remplacement :
Dim oSubFolder, oFolder, F , ffCount
Set oFolder = fso.GetFolder(sFolder)
' On Error Resume Next
If Err.Number <> 0 Then
Err.Clear
Else
If oFolder.Files.Count > 0 Then
For Each F In fso.GetFolder(oFolder.Path).Files
If Err.Number <> 0 Then
Err.Clear
Else
If Is_XSC_File(F.Path) Then
objOut.WriteLine F.Path
Set objTemp = fso.OpenTextFile(F.Path, ForReading, False)
ContentFile = objTemp.ReadAll
objTemp.Close
ContentFile = Replace(ContentFile, "Win,", "xxxx", 1, -1, vbTextCompare)
' Si la balise <div> doit contenir tout le texte après remlacement :
FinalText = "<div style=" & Chr(34) & "margin-left:40px" & Chr(34) & ">" _
& ContentFile & "</div>"
Set objTemp = fso.OpenTextFile(F.Path, ForWriting, True)
objTemp.Write FinalText
objTemp.Close
End If
End If
Next
End If
End If
'Parcours de tous les sous-dossiers du lecteur
'ou dossier s'il est ajouté en tant que paramètre pour Scan4Files
For Each oSubFolder In oFolder.SubFolders
If Err.Number <> 0 Then
Err.Clear
Else
Scan4Files oSubFolder.Path
End If
Next
End Sub
'============================
Function Is_XSC_File(strObj)
Is_XSC_File = LCase(fso.GetExtensionName(strObj)) = "xsc"
End Function |
Partager