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
Dim MasterFolderPath,fso,File,Folder,ws,LogFile
MasterFolderPath = "C:\Users\Hackoo\Desktop\Hackoo\" '<===== Changer juste cette ligne à la votre
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(MasterFolderPath)
Set ws = CreateObject("Wscript.Shell")
LogFile = "Bilan.txt"
if fso.FileExists(LogFile) Then
fso.DeleteFile LogFile
end If
for each file in folder.Files
if Lcase(fso.getExtensionName(file.path)) = "txt" then
Call WriteLog(ExtractLinesFromTextFile(file,1,2),LogFile)
end if
Next
ws.run LogFile
'*********************************************************************************************************
Public Function ExtractLinesFromTextFile(ByRef TextFile, ByRef FromLine, ByRef ToLine) '<-- Inclusive
If FromLine <= ToLine Then
With CreateObject("Scripting.FileSystemObject").OpenTextFile(TextFile)
Do Until .Line = FromLine Or .AtEndOfStream
.SkipLine
Loop
Do Until .Line > ToLine Or .AtEndOfStream
ExtractLinesFromTextFile = ExtractLinesFromTextFile & (.ReadLine & vbNewLine)
Loop
End With
Else
wscript.echo "erreur de depassement de lignes", vbCritical, "erreur de depassement de lignes"
End If
End Function
'*********************************************************************************************************
Sub WriteLog(strText,LogFile)
Dim fs,ts
Const ForAppending = 8
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(LogFile,ForAppending,True,-1)
ts.WriteLine strText
ts.Close
End Sub
'********************************************************************************************************* |
Partager