DonationCoder.com Software > Post New Requests Here
IDEA: Search Txt files export data
Earthcoder:
Hello,
Wondered if you can help, I am looking for a script or program, that will search a folder full of text files, then pull data lines from txt file and place into a database or CSV file.
Example of a txt file (there 2,000 files)
System Snapshot - Tue 10/04/2007 8:46:05.46
Last User: s2101389
System Name: C09730
System Manufacturer: Viglen
System Model: GENIE D865GLC
BIOS Manufacturer: Intel Corp.
BIOS Version: BIOS Date: 01/22/04 09:53:47 Ver: 08.00.10
BIOS Serial Number: 1739056
Processor: Intel(R) Pentium(R) 4 CPU 2.80GHz 2793MHz
OS Name: Microsoft Windows 2000 Professional
OS Version: 5.0.2195
Service Pack: 4
Windows Directory: C:\WINNT
Locale: English United States
Total Physical Memory: 511MB
Free Physical Memory: 160MB
Total Disk Space (SystemDrive): 33503MB
Free Disk Space (SystemDrive): 11043MB
Internet Explorer Version: 6.0.2800.1106
Current Users Profile: C:\Documents and Settings\s2101307
Windows 2000 IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : chelt.local
Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connection
Physical Address. . . . . . . . . : 00-0C-F1-E1-41-81
IP Address. . . . . . . . . . . . : 10.59.11.241
Lease Obtained. . . . . . . . . . : 10 April 2007 08:41:48
Lease Expires . . . . . . . . . . : 18 April 2007 08:41:48
Software Installed
List of all software installed
Printer Connections
Server name
Printer name Microsoft Office Document Image Writer
Share name
Driver name Microsoft Office Document Image Writer Driver
Port name Microsoft Document Imaging Writer Port:
Location
Print processor ModiPrint
Data type RAW
Attributes 64
Default priority 0
Status Unknown
Average pages per minute 0
Server name
Printer name \\c12214\ICT RICOH Aficio 2020D PCL 6
Share name ICT OFFICE
Driver name RICOH Aficio 2020D PCL 6
Port name EQ_IP_10.59.1.233
Location PARK, LC004, ICT Office
Print processor WinPrint
Data type RAW
Attributes 540
Default priority 0
Start time 00h00
Until time 00h00
Status Unknown
Average pages per minute 0
Basically What i wanted, is a script or program that searches this files and caprures the follow info in a csv - The whole lines.
System Snapshot:
Last User:
System Name:
Processor:
Total Physical Memory:
Free Physical Memory:
Total Disk Space (SystemDrive):
Free Disk Space (SystemDrive):
Physical Address. . . . . . . . . :
IP Address. . . . . . . . . . . . :
Software Installed: (List in one field spaced)
Printer name:
If possiable all the required names as fields then all the details in one csv, If not just csv per file.
I been searching net all morning for something that would do it but cant find one.
If not possiable please let me know
tinjaw:
Earthcoder,
:huh: Please provide a sample of what the CSV files should look like based on the TXT file you provided. That might help to scope out the complexity of what is requested.
Earthcoder:
Would be ideal if all files were added to one csv EG:
--- ---System Snapshot:,Last User:,System Name:,Processor: ,Total Physical Memory: ,Free Physical Memory: ,Total Disk Space,Free Disk Space,Physical Address.,IP Address.,Software Installed: ,Printer name:
Date,s2101307,c09730, Intel(R) Pentium(R) 4 CPU 2.80GHz 2793MHz,511MB,160MB,33503MB,11043MB,00-0C-F1-E1-41-81,10.59.11.241,office PDF Photoshop etc, \\c12214\ICT RICOH Aficio 2020D PCL 6
next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file,next text file
Or if Single Just ignore Next text file
Or anyother way u can suggest would be good.
I run a Inventory system of computers on the network, and before i had to do them all manually, importing into a sql database, But thought it would be easier if just used a system snapshot, then import into the sql file, every week or too with the latest updates.
Csv is easy to work with, But access or Sql can be ok too, just a database of all the content of the files.
If there no way around this then ill have to think of somthing else.
tinjaw:
What you are asking for is probably doable, but would require a lot of hard coding to get only the info you wanted out of the report. (From just a quick look at things.) How much leeway do you have? You could use WMI and gather the info that you wanted, even remotely, and put it in a CSV or straight into the SQL server.
Also, have you looked into freeware tools like WinAudit and Belarc Advisor?
e_murf1:
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, 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, 8)
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
Navigation
[0] Message Index
[#] Next page
Go to full version