C# comparing two files regex problem.

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-08T17:13:45Z Indexed on 2010/03/08 17:21 UTC
Read the original article Hit count: 205

Filed under:

Hi everyone, what I'm trying to do is open a huge list of files (about 40k records, and match them on a line in a file that contains 2 millions records. And if my line from file A matches a line in file B write out that line.

File A contains a bunch of files without extensions and file B contains full file paths including extensions.

i'm using this but i cant get it to go...

string alphaFilePath = (@"C:\Documents and Settings\g\Desktop\Arrp\Find\natst_ready.txt");

            List<string> alphaFileContent = new List<string>();

            using (FileStream fs = new FileStream(alphaFilePath, FileMode.Open))
            using (StreamReader rdr = new StreamReader(fs))
            {
                while (!rdr.EndOfStream)
                {
                    alphaFileContent.Add(rdr.ReadLine());
                }
            }

            string betaFilePath = @"C:\Documents and Settings\g\Desktop\Arryup\Find\eble.txt";

            StringBuilder sb = new StringBuilder();

            using (FileStream fs = new FileStream(betaFilePath, FileMode.Open))
            using (StreamReader rdr = new StreamReader(fs))
            {
                while (!rdr.EndOfStream)
                {
                    string betaFileLine = rdr.ReadLine();
string matchup = Regex.Match(alphaFileContent, @"(\\)(\\)(\\)(\\)(\\)(\\)(\\)(\\)(.*)(\.)").Groups[9].Value;
                    if (alphaFileContent.Equals(matchup))
                    {
                        File.AppendAllText(@"C:\array_tech.txt", betaFileLine);
                    }
                }
            }

This doesnt work because the alphafilecontent is a single line only and i'm having a hard time figuring out how to get my regex to work on the file that contains all the file paths (Betafilepath)

here is a sample of the beta file path.

C:\arres_i\Grn\Ora\SEC\DBZ_EX1\Nes\001\DZO-EX00001.txt

Here is the line i'm trying to compare from my alpha DZO-EX00001

© Stack Overflow or respective owner

Related posts about c#