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
| Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim stRep 'Nom du répertoire à parcourir
Dim oFSO,oFl,Ext,ReadFile,strLine,OutPutFile,i
'ici dans ce tableau vous pouvez ajouter d'autres extensions de type texte
Ext = Array(".txt",".asp",".php",".rtf",".html",".htm",".hta",".xml",".csv",".vbs",".js",".css",".ini",".inf")
Set oFSO = CreateObject("Scripting.FileSystemObject")
stRep = Parcourir_Dossier()
MsgBox qq(stRep),64,"Chemin du dossier à traiter"
If oFSO.FolderExists(stRep) Then
For each oFl in oFSO.GetFolder(stRep).Files
For i=LBound(Ext) To UBound(Ext)
If Instr(lcase(oFl.name),Ext(i)) > 0 And oFl.size <> 0 Then
Set ReadFile = oFSO.OpenTextFile(oFl,ForReading)'Ouvrir le fichier en lecture Seule
strLine = ReadFile.ReadAll 'Lecture de la totalité du fichier
Set OutPutFile = oFSO.OpenTextFile(oFl,ForWriting) 'Ouvrir le fichier en écriture
strLine = Replace(strLine,"AAAAA","BBBBB")
strLine = Replace(strLine,"CCCCC","ZZZZZ")
OutPutFile.WriteLine strLine
MsgBox strLine,64,"Le fichier "& qq(oFl.name)
End if
Next
Next
End If
'***************************************************************************************************
Function Parcourir_Dossier()
Dim objShell,objFolder,NomDossier
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Veuillez choisir un dossier pour le traitement !",1,"c:\Programs")
If objFolder Is Nothing Then
Wscript.Quit
End If
NomDossier = objFolder.title
Parcourir_Dossier = objFolder.self.path
end Function
'***************************************************************************************************
Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function
'*************************************************************************************************** |
Partager