micropathic Posted January 18, 2004 Posted January 18, 2004 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! Quote
*Experts* mutant Posted January 18, 2004 *Experts* Posted January 18, 2004 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 don't know how many lines there are. Quote
micropathic Posted January 18, 2004 Author Posted January 18, 2004 It doesn't 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 Quote
micropathic Posted January 18, 2004 Author Posted January 18, 2004 What would be the syntax to use to fill an array using the readline method? Quote
*Experts* mutant Posted January 19, 2004 *Experts* Posted January 19, 2004 Lets you say you have an arraylist. This is how you would fill it. '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 Quote
micropathic Posted January 19, 2004 Author Posted January 19, 2004 Thanks, your help is much appreciated! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.