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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| Option Explicit
Dim LogFile,SourceFolder,objFSO,Ws
Set objFSO = CreateObject("Scripting.FileSystemObject")
LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, ".")) & "txt"
if objFSO.FileExists(LogFile) Then 'Si le fichier LogFile existe
objFSO.DeleteFile LogFile 'alors on le supprime
end If
SourceFolder = "C:\Dataexports\notes"
'msgbox SourceFolder
Call Scan4Folder(SourceFolder)
MsgBox "The script is finished by Hackoo !",VbInformation,"The script is finished by Hackoo !"
Set Ws = CreateObject("wscript.shell")
ws.run DblQuote(LogFile)
'**************************************************************************
Function Browse4Folder()
Dim objShell,objFolder,Message
Message = "Please select a folder "
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0,Message,0,0)
If objFolder Is Nothing Then
Wscript.Quit
End If
Browse4Folder = objFolder.self.path
End Function
'*********************************************************************
Function Scan4Folder(Folder)
Dim fso,objFolder,File,Excluded_File
Dim Tab,aFile,FileName,Contenu,TXT_Copied
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(Folder)
Excluded_File = "liste.txt"
For Each File in objFolder.Files
If LCase(fso.GetExtensionName(File)) = "txt" And File.Name <> Excluded_File And File.Size <> 0 Then
FileName = File.Name
Contenu = ReadFile(File,"all")
TXT_Copied = TXT_Copied & DblQuote(FileName) & vbCrLf & Contenu & vbCrLf & vbCrLf
'Msgbox "The File " & DblQuote(FileName) & " is copied on " & vbCrLf &_
'DblQuote(Contenu),vbInformation,DblQuote(File)
End If
Next
Call WriteFile(TXT_Copied,LogFile)
End Function
'*********************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************
Function ReadFile(path,mode)
Const ForReading = 1
Dim objFSO,objFile,i,contents
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(path,ForReading,-2)
If mode = "byline" then
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
strLine = objFile.ReadLine
strLine = Trim(strLine)
If Len(strLine) > 0 Then
arrFileLines(i) = strLine
i = i + 1
ReadFile = arrFileLines
End If
Loop
objFile.Close
End If
If mode = "all" Then
contents = objFile.ReadAll
ReadFile = contents
objFile.Close
End If
End Function
'*****************************************************************
'Fonction pour écrire le résultat dans un fichier texte
Sub WriteFile(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