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
| Option Explicit
public const ForReading = 1
public const ForWriting = 2
public fso, OutputFile, ProcessedFile
dim Folder, Files, File
set fso = CreateObject("Scripting.FileSystem* Object")
set Folder = fso.GetFolder(".")
set Files = Folder.Files
OutputFile = "output.csv"
CreateProcessedFile(OutputFile)
for each File in Files
if isCSV(File.Name) and File.Name <> OutputFile then
Process(File.Name)
end if
next
Function isCSV(FileName)
dim arrFilename
arrFilename = split(FileName,".")
if ubound(arrFilename) > 0 then
if lcase(arrFilename(ubound(arrFilena* me))) = "csv" then
isCSV = true
else
isCSV = false
end if
end if
End Function
Function CreateProcessedFile(FileName)
Set ProcessedFile = fso.CreateTextFile(".\" &FileName, true)
End Function
Function Process(FileName)
dim NextLine, Output, InputLine, TextFile
set TextFile = fso.OpenTextFile (".\" & FileName, ForReading)
set ProcessedFile = fso.OpenTextFile (".\" & OutputFile, ForReading)
if ProcessedFile.AtEndOfStream then
while not TextFile.AtEndOfStream
if not ProcessedFile.AtEndOfStream then
InputLine = ProcessedFile.Readline
else
InputLine = ""
end if
NextLine = TextFile.Readline
Output = Output & NextLine & vbcrlf
wend
else
while not TextFile.AtEndOfStream
if not ProcessedFile.AtEndOfStream then
InputLine = ProcessedFile.Readline
else
InputLine = ""
end if
NextLine = TextFile.Readline
Output = Output & InputLine & "," & NextLine & vbcrlf
wend
end if
WriteProcessedFile(Output)
End Function
Function WriteProcessedFile(Contents)
dim TextStream
Set ProcessedFile = fso.GetFile(".\" & OutputFile)
Set TextStream = ProcessedFile.OpenAsTextStream(For* Writing,-2)
TextStream.Write Contents
TextStream.Close
End Function |
Partager