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, ForWriting = 2
Const ModeAscii = 0, ModeUnicode = -1
Dim fso, f_in, f_out, tFile, WS, tmpName, temoin, fName, tmpFold
f_in = Wscript.Arguments(0)
Set WS = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
' Préparation du nom du fichier temporaire
tmpFold = WS.ExpandEnvironmentStrings("%Temp%")
tmpName = tmpFold & "\Temp." & fso.GetExtensionName(f_in)
fName = tmpFold & "\" & fso.GetBaseName(f_in) & ".enc"
' Vérifie si le fichier témoin existe
If fso.FileExists(fName) Then
MsgBox "Le fichier " & vbNewLine & f_in & vbNewLine & " a déjà été traité"
Wscript.Quit
End If
' Copie le fichier original dans le dossier temporaire(Temp)
fso.CopyFile fso.GetFile(f_in).Path, tmpName, True
' Création de l'objet File correspondant au fichier temporaire à lire dedans
Set tFile = fso.OpenTextFile(tmpName, ForReading, False, ModeUnicode)
'Création de l'objet File correspondant au fichier original(Wscript.Arguments(0))
Set f_out = fso.OpenTextFile(f_in, ForWriting, true, ModeAscii)
' Copie cararctère par caractère de source à cible
Do Until tFile.AtEndOfStream
f_out.Write tFile.Read(1)
Loop
' Le traitement s'est bien déroulé, on crée dans le dossier Temp
' un fichier témoin vide (ayant l'extension enc évoquant encoded) puis on le ferme
Set temoin = fso.OpenTextFile( fName, ForWriting, True)
temoin.Close
' Ferme le fichier temporaire puis le supprime
tFile.Close
fso.GetFile(tmpName).Delete True
' Ferme le fichier de sortie
f_out.Close
' Nettoyage :
Set tFile = Nothing
Set f_out = Nothing
Set fso = Nothing |
Partager