Not exactly a piece of beauty but it appears to do the trick for me. Have you an FTP that I can upload the .exe and xml to? My webmail might let me e-mail it to you, work mail will definitely block it.
Eoghan
Imports System.IO
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents InDirBut As System.Windows.Forms.Button
Friend WithEvents OutDirBut As System.Windows.Forms.Button
Friend WithEvents InDirTB As System.Windows.Forms.TextBox
Friend WithEvents OutDirTB As System.Windows.Forms.TextBox
Friend WithEvents StartBut As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.InDirBut = New System.Windows.Forms.Button
Me.OutDirBut = New System.Windows.Forms.Button
Me.InDirTB = New System.Windows.Forms.TextBox
Me.OutDirTB = New System.Windows.Forms.TextBox
Me.StartBut = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'InDirBut
'
Me.InDirBut.Location = New System.Drawing.Point(8,
Me.InDirBut.Name = "InDirBut"
Me.InDirBut.Size = New System.Drawing.Size(88, 24)
Me.InDirBut.TabIndex = 0
Me.InDirBut.Text = "Input Folder"
'
'OutDirBut
'
Me.OutDirBut.Location = New System.Drawing.Point(8, 32)
Me.OutDirBut.Name = "OutDirBut"
Me.OutDirBut.Size = New System.Drawing.Size(88, 24)
Me.OutDirBut.TabIndex = 1
Me.OutDirBut.Text = "Output Folder"
'
'InDirTB
'
Me.InDirTB.Location = New System.Drawing.Point(96,
Me.InDirTB.Name = "InDirTB"
Me.InDirTB.Size = New System.Drawing.Size(664, 20)
Me.InDirTB.TabIndex = 2
Me.InDirTB.Text = "E:\test"
'
'OutDirTB
'
Me.OutDirTB.Location = New System.Drawing.Point(96, 32)
Me.OutDirTB.Name = "OutDirTB"
Me.OutDirTB.Size = New System.Drawing.Size(664, 20)
Me.OutDirTB.TabIndex = 3
Me.OutDirTB.Text = "E:\test"
'
'StartBut
'
Me.StartBut.Location = New System.Drawing.Point(320, 64)
Me.StartBut.Name = "StartBut"
Me.StartBut.Size = New System.Drawing.Size(96, 24)
Me.StartBut.TabIndex = 4
Me.StartBut.Text = "Start"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(768, 102)
Me.Controls.Add(Me.StartBut)
Me.Controls.Add(Me.OutDirTB)
Me.Controls.Add(Me.InDirTB)
Me.Controls.Add(Me.OutDirBut)
Me.Controls.Add(Me.InDirBut)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Parser Thing"
Me.ResumeLayout(False)
End Sub
#End Region
Dim AL As New ArrayList
Dim ARR(,) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
'xml document object
Dim xd As New Xml.XmlDocument
'load the xml file
xd.Load(Application.StartupPath & "\IncludeTheseNamesInCSV.xml")
Dim Node As XmlNode = xd.SelectSingleNode("//INCLUDE")
Dim ChildNode As XmlNode
For Each ChildNode In Node
AL.Add(ChildNode.InnerText)
Next
ReDim ARR(AL.Count - 1, 0)
Dim s As String
Dim i As Integer = 0
For Each s In AL
ARR(i, 0) = s
i += 1
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub StartBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBut.Click
Try
If InDirTB.Text = "" Then
MsgBox("Input directory does not exist")
Exit Sub
End If
Dim dirIn As New DirectoryInfo(InDirTB.Text.Trim)
If dirIn.Exists = False Then
MsgBox("Input directory does not exist")
Exit Sub
End If
If OutDirTB.Text = "" Then
MsgBox("Output directory does not exist")
Exit Sub
End If
Dim dirOut As New DirectoryInfo(InDirTB.Text.Trim)
If dirOut.Exists = False Then
MsgBox("Output directory does not exist")
Exit Sub
End If
Dim fi As FileInfo
For Each fi In dirIn.GetFiles
If fi.Extension = ".txt" Then
If CheckForRequiredText(fi.FullName) = True Then
GetRequiredText(fi.FullName)
End If
End If
Next
Dim i As Integer = 0
Dim FileOut As New FileInfo(dirOut.FullName & "\Output-" & i & ".csv")
While FileOut.Exists = True
i = i + 1
FileOut = New FileInfo(dirOut.FullName & "\Output-" & i & ".csv")
End While
Dim Count1 As Integer = 0
Dim Count2 As Integer = 0
Dim LineOut As String = ""
Dim SW As New StreamWriter(dirOut.FullName & "\Output-" & i & ".csv")
For Count1 = 0 To ARR.GetUpperBound(1)
LineOut = ""
For Count2 = 0 To ARR.GetUpperBound(0)
LineOut = LineOut & ARR(Count2, Count1) & ","
Next
SW.WriteLine(LineOut)
Next
SW.Close()
MsgBox("FINISHED")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Function CheckForRequiredText(ByVal FileIn As String) As Boolean
Try
Dim oFileIn As String
Dim SR As New StreamReader(FileIn)
oFileIn = SR.ReadToEnd
SR.Close()
Dim s As String
For Each s In AL
If InStr(oFileIn, s) = 0 Then Return False
Next
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Private Function GetRequiredText(ByVal FileIn As String) As Boolean
Try
ReDim Preserve ARR(ARR.GetUpperBound(0), ARR.GetUpperBound(1) + 1)
Dim oLineIn As String
Dim SR As New StreamReader(FileIn)
oLineIn = SR.ReadLine
While Not (oLineIn Is Nothing)
Dim i As Integer = 0
Dim s As String
For Each s In AL
If InStr(oLineIn, s) > 0 Then
Dim str As String = oLineIn
str = Replace(str, s, "")
str = str.Trim
ARR(i, ARR.GetUpperBound(1)) = str
End If
i += 1
Next
oLineIn = SR.ReadLine
End While
SR.Close()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Private Sub InDirBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InDirBut.Click
Try
Dim dialog As New FolderBrowserDialog
Dim Result As DialogResult = dialog.ShowDialog()
If Result <> DialogResult.OK Then Exit Sub
If dialog.SelectedPath.ToString = "" Then Exit Sub
InDirTB.Text = dialog.SelectedPath.ToString
dialog.Dispose()
dialog = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub OutDirBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutDirBut.Click
Try
Dim dialog As New FolderBrowserDialog
Dim Result As DialogResult = dialog.ShowDialog()
If Result <> DialogResult.OK Then Exit Sub
If dialog.SelectedPath.ToString = "" Then Exit Sub
OutDirTB.Text = dialog.SelectedPath.ToString
dialog.Dispose()
dialog = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class