Compare text files with directory listing

micropathic

Well-known member
Joined
Oct 23, 2003
Messages
75
How can I load the contents of a text file into an array and compare it with the contents of another text file? For instance, if I have a text file with a listing of all the files in a directory with on file listed on each line of the text file, how can I read line by line from that text file to see if another text file contains the file listed in each line? For instance, if my directory listing in text file 1 looks like this:

C:\3dlogo.gif
C:\654-7303 Window Guy.txt
C:\AUTOEXEC.BAT
C:\boot.ini
C:\BOXBOY.NES
C:\capture.avi
C:\cedb.dll
C:\command.com
C:\CONFIG.SYS
C:\Ctp.log
C:\devbld.pkg
C:\devcpu.pkg

How can I look in text file 2 to see if the text "C:\3dlogo.gif" exists and then see if the text "C:\654-7303 Window Guy.txt" exists, and so on.

Thanks for any help in advance!
 
Are the matching file names supposed to be in the same line? Or it doesnt matter which line they are on?
To load the lines from the text file, you would use the System.IO.StreamReader class. Then using its ReadLine method, fill in an array, or an arraylist if you dont know how many lines there are.
 
It doesnt matter which line it is on for my purposes. What matters is if the name of the file in text file 1 exists at all in text file 2.

Thanks
 
Lets you say you have an arraylist. This is how you would fill it.
Code:
Create a new ArrayList to store the contents of the file
Dim arrl As New ArrayList
Create a new StreamReader to read the file
dim reader As New IO.StreamReader(path to the file")
Try to read while there is something to read
Do WHile reader.Peek()
     Add a line from the text file to the array
    arrl.Add(reader.ReadLine())
Loop
then do the same for the next file
 
Back
Top