|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Looping through files to compareI'm lookin for a very confusing loop (to me), to compare two files. Here it is. I have two arrays with paths stored in both. example: /en/aviation/you.htm. I need to search array two for all the paths in array 1. If it finds it, send it to array 3. Here's my code to send it to the array. Dim sr As IO.StreamReader = IO.File.OpenText(File1) 'Loop through Directory Listing file to load filepaths into an array While sr.Peek <> -1 'Count the number of lines (for the arrays), and read in the lines counter += 1 lineFile1 = sr.ReadLine 'Re-Dimension the array to hold "counter" number of elements ReDim InternetDirectoryArray(counter) 'String Manipulation (Replace some unneeded text) MyString = lineFile1 Dim sb As New System.Text.StringBuilder(MyString) sb.Replace("C:", "") sb.Replace("x:", "") sb.Replace("\", "/") sb.Replace("wwwroot", "") MyString = sb.ToString() InternetDirectoryArray(counter) = MyString End While 'Close the first file sr.Close() 'Open the second file sr = IO.File.OpenText(File2) i = 0 i2 = 0 counter2 = 0 Do While sr.Peek <> -1 counter2 += 1 lineFile2 = sr.ReadLine MyString2 = lineFile2 Dim sb2 As New System.Text.StringBuilder(MyString2) sb2.Replace("C:", "") sb2.Replace("x:", "") sb2.Replace("\", "/") sb2.Replace("wwwroot", "") MyString2 = sb2.ToString() ReDim Preserve IISLogArray(counter2) IISLogArray(counter2) = MyString2 Loop -------------------------------------------------------------------- I've tried for hours on how to get the logic down, but its confusing me too much. Maybe someone know's what to do. Thanks for your help. Justin One more thing, Here's the code i've tried to tamper with, and it looks
right? Just not executing the way I want it to? For i = 0 To counter If MyString2 <> InternetDirectoryArray(i) Then MsgBox("This is not working") End If Next 'lstDisplay.Items.Add(ZeroHits(i2)) This code is inside the second Do While loop, comparing it to the 1st array. I've tested it by putting msgbox's in between the if statement, but it doesn't work. How do i know that? Well, I put two of the same text files i'm reading in the same. Each line in each file are identical. So, if the code was executing the way I wanted it to, it wouldn't display the message box. But it does, repeatidly. Justin Justin,
basically what I'm hearing is that you're going to have to do the following: Load array1 with paths from a file Load array2 with paths from a file for every item in array1, loop through array2 to see if there is a match. That sounds really slow to me. I think I'd load the items into a dictionary or collection of some kind to make the searchs faster. Load file1 into a collection load file2 into a collection for every item in collection1, if collection2.item(item) then do something with it end if next Just a thought Steve Show quoteHide quote "Justin Fancy" <justinfa***@gmail.com> wrote in message news:1161713124.390584.6690@b28g2000cwb.googlegroups.com... > Hi Everyone, > > I'm lookin for a very confusing loop (to me), to compare two files. > Here it is. I have two arrays with paths stored in both. example: > /en/aviation/you.htm. > > I need to search array two for all the paths in array 1. If it finds > it, send it to array 3. > > Here's my code to send it to the array. > > Dim sr As IO.StreamReader = IO.File.OpenText(File1) > > 'Loop through Directory Listing file to load filepaths into an > array > While sr.Peek <> -1 > > 'Count the number of lines (for the arrays), and read in > the lines > counter += 1 > lineFile1 = sr.ReadLine > > 'Re-Dimension the array to hold "counter" number of > elements > ReDim InternetDirectoryArray(counter) > > 'String Manipulation (Replace some unneeded text) > MyString = lineFile1 > > Dim sb As New System.Text.StringBuilder(MyString) > sb.Replace("C:", "") > sb.Replace("x:", "") > sb.Replace("\", "/") > sb.Replace("wwwroot", "") > MyString = sb.ToString() > > InternetDirectoryArray(counter) = MyString > > End While > 'Close the first file > sr.Close() > > > 'Open the second file > sr = IO.File.OpenText(File2) > i = 0 > i2 = 0 > counter2 = 0 > > Do While sr.Peek <> -1 > > counter2 += 1 > lineFile2 = sr.ReadLine > MyString2 = lineFile2 > Dim sb2 As New System.Text.StringBuilder(MyString2) > sb2.Replace("C:", "") > sb2.Replace("x:", "") > sb2.Replace("\", "/") > sb2.Replace("wwwroot", "") > MyString2 = sb2.ToString() > ReDim Preserve IISLogArray(counter2) > IISLogArray(counter2) = MyString2 > > Loop > > -------------------------------------------------------------------- > > I've tried for hours on how to get the logic down, but its confusing me > too much. Maybe someone know's what to do. > > Thanks for your help. > > Justin > Opps, this code:
if collection2.item(item) then should have read like this: if not collection2.item(item) is nothing then 'do something end if S Show quoteHide quote "Steve Long" <Steve_Noneya@NoSpam.com> wrote in message news:etN0e559GHA.3344@TK2MSFTNGP03.phx.gbl... > Justin, > basically what I'm hearing is that you're going to have to do the > following: > Load array1 with paths from a file > Load array2 with paths from a file > for every item in array1, loop through array2 to see if there is a match. > > That sounds really slow to me. I think I'd load the items into a > dictionary or collection of some kind to make the searchs faster. > Load file1 into a collection > load file2 into a collection > > for every item in collection1, > if collection2.item(item) then > do something with it > end if > next > > Just a thought > Steve > > > "Justin Fancy" <justinfa***@gmail.com> wrote in message > news:1161713124.390584.6690@b28g2000cwb.googlegroups.com... >> Hi Everyone, >> >> I'm lookin for a very confusing loop (to me), to compare two files. >> Here it is. I have two arrays with paths stored in both. example: >> /en/aviation/you.htm. >> >> I need to search array two for all the paths in array 1. If it finds >> it, send it to array 3. >> >> Here's my code to send it to the array. >> >> Dim sr As IO.StreamReader = IO.File.OpenText(File1) >> >> 'Loop through Directory Listing file to load filepaths into an >> array >> While sr.Peek <> -1 >> >> 'Count the number of lines (for the arrays), and read in >> the lines >> counter += 1 >> lineFile1 = sr.ReadLine >> >> 'Re-Dimension the array to hold "counter" number of >> elements >> ReDim InternetDirectoryArray(counter) >> >> 'String Manipulation (Replace some unneeded text) >> MyString = lineFile1 >> >> Dim sb As New System.Text.StringBuilder(MyString) >> sb.Replace("C:", "") >> sb.Replace("x:", "") >> sb.Replace("\", "/") >> sb.Replace("wwwroot", "") >> MyString = sb.ToString() >> >> InternetDirectoryArray(counter) = MyString >> >> End While >> 'Close the first file >> sr.Close() >> >> >> 'Open the second file >> sr = IO.File.OpenText(File2) >> i = 0 >> i2 = 0 >> counter2 = 0 >> >> Do While sr.Peek <> -1 >> >> counter2 += 1 >> lineFile2 = sr.ReadLine >> MyString2 = lineFile2 >> Dim sb2 As New System.Text.StringBuilder(MyString2) >> sb2.Replace("C:", "") >> sb2.Replace("x:", "") >> sb2.Replace("\", "/") >> sb2.Replace("wwwroot", "") >> MyString2 = sb2.ToString() >> ReDim Preserve IISLogArray(counter2) >> IISLogArray(counter2) = MyString2 >> >> Loop >> >> -------------------------------------------------------------------- >> >> I've tried for hours on how to get the logic down, but its confusing me >> too much. Maybe someone know's what to do. >> >> Thanks for your help. >> >> Justin >> > > Sorry, I'm not up on using collections at all.
I dont have the code with me now, but I did get the logic down, but I can't seem to get it working. I'll message tomorrow morning. Thanks for your help Steve. Much appreciated. J Steve Long wrote: Show quoteHide quote > Opps, this code: > if collection2.item(item) then > > should have read like this: > > if not collection2.item(item) is nothing then > 'do something > end if > > S > > "Steve Long" <Steve_Noneya@NoSpam.com> wrote in message > news:etN0e559GHA.3344@TK2MSFTNGP03.phx.gbl... > > Justin, > > basically what I'm hearing is that you're going to have to do the > > following: > > Load array1 with paths from a file > > Load array2 with paths from a file > > for every item in array1, loop through array2 to see if there is a match. > > > > That sounds really slow to me. I think I'd load the items into a > > dictionary or collection of some kind to make the searchs faster. > > Load file1 into a collection > > load file2 into a collection > > > > for every item in collection1, > > if collection2.item(item) then > > do something with it > > end if > > next > > > > Just a thought > > Steve > > > > > > "Justin Fancy" <justinfa***@gmail.com> wrote in message > > news:1161713124.390584.6690@b28g2000cwb.googlegroups.com... > >> Hi Everyone, > >> > >> I'm lookin for a very confusing loop (to me), to compare two files. > >> Here it is. I have two arrays with paths stored in both. example: > >> /en/aviation/you.htm. > >> > >> I need to search array two for all the paths in array 1. If it finds > >> it, send it to array 3. > >> > >> Here's my code to send it to the array. > >> > >> Dim sr As IO.StreamReader = IO.File.OpenText(File1) > >> > >> 'Loop through Directory Listing file to load filepaths into an > >> array > >> While sr.Peek <> -1 > >> > >> 'Count the number of lines (for the arrays), and read in > >> the lines > >> counter += 1 > >> lineFile1 = sr.ReadLine > >> > >> 'Re-Dimension the array to hold "counter" number of > >> elements > >> ReDim InternetDirectoryArray(counter) > >> > >> 'String Manipulation (Replace some unneeded text) > >> MyString = lineFile1 > >> > >> Dim sb As New System.Text.StringBuilder(MyString) > >> sb.Replace("C:", "") > >> sb.Replace("x:", "") > >> sb.Replace("\", "/") > >> sb.Replace("wwwroot", "") > >> MyString = sb.ToString() > >> > >> InternetDirectoryArray(counter) = MyString > >> > >> End While > >> 'Close the first file > >> sr.Close() > >> > >> > >> 'Open the second file > >> sr = IO.File.OpenText(File2) > >> i = 0 > >> i2 = 0 > >> counter2 = 0 > >> > >> Do While sr.Peek <> -1 > >> > >> counter2 += 1 > >> lineFile2 = sr.ReadLine > >> MyString2 = lineFile2 > >> Dim sb2 As New System.Text.StringBuilder(MyString2) > >> sb2.Replace("C:", "") > >> sb2.Replace("x:", "") > >> sb2.Replace("\", "/") > >> sb2.Replace("wwwroot", "") > >> MyString2 = sb2.ToString() > >> ReDim Preserve IISLogArray(counter2) > >> IISLogArray(counter2) = MyString2 > >> > >> Loop > >> > >> -------------------------------------------------------------------- > >> > >> I've tried for hours on how to get the logic down, but its confusing me > >> too much. Maybe someone know's what to do. > >> > >> Thanks for your help. > >> > >> Justin > >> > > > > Steve Long wrote:
> Justin, Load array1 into a hashtable. then load array2 into the same table.> basically what I'm hearing is that you're going to have to do the following: > Load array1 with paths from a file > Load array2 with paths from a file > for every item in array1, loop through array2 to see if there is a match. If you get an error 5 it means that the item already exists so you can add that item to array 3. Hugh Right Hugh, but, the problem with this method is that a exception is
thrown--which is very expensive in terms of processor time. However, the other method of checking to see if an item exists in a collection should be faster. Maybe.... ???? Steve Show quoteHide quote "Hugh Janus" <my-junk-acco***@hotmail.com> wrote in message news:1161759041.156039.324760@f16g2000cwb.googlegroups.com... > > Steve Long wrote: >> Justin, >> basically what I'm hearing is that you're going to have to do the >> following: >> Load array1 with paths from a file >> Load array2 with paths from a file >> for every item in array1, loop through array2 to see if there is a match. > > Load array1 into a hashtable. then load array2 into the same table. > If you get an error 5 it means that the item already exists so you can > add that item to array 3. > > Hugh >
Systray Icon
Regular Expressions .NET Issue with VB6 using a .NET DLL on one PC with Windows 2000 Server how to round number to custom step (0.25, 20, 100...) Determine what current drive letter is? Collection Question audio functions in Winmm.dll Quick SQLclient Data Access ASPX / VB .NET Compilation in dot NET Shared Compression for VB.NET and PHP |
|||||||||||||||||||||||