[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how can i get rid of white space and parse this info

Posted on 2004-11-18
4
Medium Priority
?
175 Views
Last Modified: 2010-04-23
i have a text file of Tmp.txt with the below info

-------------- tmp.txt file info --------------

drwxrw-rw-   1 user     group           0 Oct 18 16:03 DefaultPage
-rw-rw-rw-   1 user     group        3638 Jun  3  2001 favicon.ico
drwxrw-rw-   1 user     group           0 Oct 18 16:03 Gallary
-rw-rw-rw-   1 user     group        3027 Oct 18 01:52 index.htm
-rw-rw-rw-   1 user     group        3383 Oct 18 02:13 index_org.php
drwxrw-rw-   1 user     group           0 Oct 18 16:03 Jayna Tags
-rw-rw-rw-   1 user     group       11603 Oct 18 01:52 ledunder.gif
drwxrw-rw-   1 user     group           0 Nov  3 21:17 TD
drwxrw-rw-   1 user     group           0 Oct 18 16:03 WildcatZips

------------- end tmp.txt file info -----------
i want to pull the below info from it
dir permissions
file size
month
day
time
file name

ive tryed the below code it reads the lines fine but to get the info into a array i seam to be having problems

it seams that dir and files have diffrent info so ive checked for that via first chr d id for dir and - is for file
but it seams the array fields are really messed up in the below example the dirs work fine its the files im having problems with
i think its due to whitespace so if i compress the info and make it read one space between fields i think it will work ok.
i tryed to do that with the sep area but it seams to not be working any ideas???

thx
Johnny
aka Pern

----------code --------------
       If System.IO.File.Exists("Tmp.txt") Then
            ''MsgBox("Exists!")
            Dim File As IO.StreamReader = IO.File.OpenText("Tmp.txt")
            Dim lines() As String = Split(File.ReadToEnd(), ControlChars.CrLf) 'split it up via the new line chars (Cr & Lf)
            File.Close()
            'Dim myArray(24) As String
            Dim intArray As Integer
            Dim File_Icon, File_IconTxt, File_Permissions_Txt As String
            Dim dir_perm, file_size, file_month, file_day, file_time, file_name As String
            intArray = 0
            Do While intArray < UBound(lines) - 1
                Dim myString As String = lines(intArray)
                Dim seperators() As Char = {" "c, Chr(10), Chr(13), vbTab}
                Dim myArray() As String = myString.Split(seperators)
                intArray = intArray + 1
                ''Label4.Text = Input(1, 1)
                '* 0 - dir permissions - 0
                '* 20 - file size - 16
                '* 21 - month - 17
                '* 22 - day - 18
                '* 23 - time - 19
                '* 24 - file name - 20
                File_Permissions_Txt = Mid(myArray(0), 1, 1)
                Select Case File_Permissions_Txt
                    Case "d"
                        ''dir
                        'dir_perm, file_size, file_month, file_day, file_time, file_name
                        ''dir_perm = myArray(0)
                        file_size = myArray(20)
                        file_month = myArray(21)
                        file_day = myArray(22)
                        file_time = myArray(23)
                        file_name = myArray(24)
                    Case "-"
                        ''file
                        'dir_perm, file_size, file_month, file_day, file_time, file_name
                        ''dir_perm = myArray(0)
                        file_size = myArray(16)
                        file_month = myArray(17)
                        file_day = myArray(18)
                        file_time = myArray(19)
                        file_name = myArray(20)
                    Case "l"
                        File_Icon = "Link"
                End Select
                '            
loop
end if
-------------------- end code ------------------
0
Comment
Question by:Johnny
  • 2
4 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12622430
Hi Pern

I tried to analyze your Log File but there are certain discrepancies there, which is making it difficult to develop a robust code for parsing the file. I think that's why you are having some problems as well.

For eg. the 2nd line of your file does not contain any Time at all

-rw-rw-rw-   1 user     group        3638 Jun  3  2001 favicon.ico

here we have the Year (2001) instead, Now this yesr is not there in any other line

Again if you look at the line

drwxrw-rw-   1 user     group           0 Oct 18 16:03 Jayna Tags

There's a space between Jayna & tags

So you see if you can not depend upon Space to act as separator as 2001 will be picked up as Time then
Also if you get a string like
-rw-rw-rw-   1 user     group        3638 Jun  3  2001 Jayna Tags
worst still,
So what I feel is you should look for more log files and try to decipher a clear pattern (strike out a few exceptions that might oocuur due to some Error in generating this log)

Also I saw your earlier post where you wanted this to be displayed in HTML, so in that case you might avoid separating the values in a line and just get the File permission stuff and work on it...

0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 12624536
here is some VB 6 code (which should work essentially as is in .NET):
this will parse the ENTIRE string into ALL of its componets, you can then use the ones that you need.


Private Sub cmdParse_Click()
Dim args() As String
Dim iCol As Integer
If Len(txtSource.Text) > 0 Then
    args = Split(txtSource.Text, " ")
    txtPermissions.Text = args(0)
    iCol = 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtType.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtUser.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtGroup.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtSize.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtMonth.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtDay.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtTime.Text = args(iCol)
    iCol = iCol + 1
    Do While args(iCol) = ""
        iCol = iCol + 1
    Loop
   
    txtName.Text = args(iCol)
   
End If
End Sub
0
 

Author Comment

by:Johnny
ID: 12626341
Arthur_Wood,

absolutly fantastic it works great

dang ive been banging my head about this


how it works id be interested in knowing...

BUT IT WORKS !!!!!!!!!!!!! yipppppeeee

thx
Johnny
aka Pern
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12631062
the split function breaks up the string into pieces, using a sincle balnk ' ' as the separator.  where there are multiple blanks, you get '' (a zero length string) for each of the multiple blanks.  The loops are there to skipp the '' entries in the resulting array created by the Split Function - look up the Split function in the VB.NET help system.

AW
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question