Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f_in, f_out
Dim file_in, file_out
Set fso = CreateObject("Scripting.FileSystemObject" )
file_in = "fichier_abc.txt"
file_out = fso.GetBaseName(file_in) & "_new.txt"
Set f_in = fso.OpenTextFile(file_in, ForReading)
Set f_out = fso.OpenTextFile(file_out, ForWriting, true)
i = 1
Do Until f_in.AtEndOfStream
text_line = f_in.ReadLine
If (InStr(text_line, " ABC " ) > 0) Then
new_chaine = " " & Right("000" & i, 3) & " "
text_line = Replace(text_line, " ABC ", new_chaine)
i = i + 1
End If
f_out.WriteLine text_line
Loop
f_in.Close
f_out.Close
' Remplace l'ancien fichier par le nouveau fichier
' (mis en commentaires pendant les tests)
'fso.DeleteFile file_in, true
'fso.MoveFile file_out, file_in
WScript.Echo "Fin" |