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
| Option Explicit
Dim ws,Title,LogFile
Title = "SkipLine Method"
Set ws = CreateObject("Wscript.Shell")
WriteLog(SkipLineInFile(2,2))
MsgBox SkipLineInFile(2,2),64,Title
LogFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log"
ws.run LogFile
'***************************************************************************************
Function SkipLineInFile(n,m)
Const ForReading = 1, ForWriting = 2
Dim fso,f,i,j,LireTout,MyArray,MyText
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "1ere Line" & vbCrLf &"2eme Line" & vbCrLf &"VBScript" & vbCrLf & "est Cool !"& vbCrLf &"6 Line" & vbCrLf &"7 Line"
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
For i = 1 To n
f.SkipLine
Next
Mytext = ""
LireTout = f.ReadAll
MyArray = Split(LireTout,vbCrLf)
For j = LBound(MyArray) To Ubound(MyArray) - m
MyText = Mytext & MyArray(j) & vbCrLf
Next
SkipLineInFile = MyText
End Function
Sub WriteLog(strText)
Dim fs,ts,LogFile
Const ForAppending = 8
LogFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log"
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.FileExists(LogFile) Then
fs.DeleteFile LogFile
end if
Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
ts.WriteLine strText
ts.Close
End Sub |
Partager