0 Replies - 482 Views - Last Post: 14 April 2012 - 09:37 AM Rate Topic: -----

#1 mrapoc   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-April 12

How to match contents from one array to another using md5hash

Posted 14 April 2012 - 09:37 AM

Hello

I'm pretty much a beginner. The scenario I face is to basically get the contents of array called search, get md5hash of each file found in the search and then compare to a "signature" file (a txt document where md5 hash strings can be determined).

If a file's md5 matches a signature then the file is listed and a message is displayed.
I can populate both arrays fine, its just the mechanism to compare between the two. So far I have:

try
            {
                string[] search = Directory.GetFiles(@folderBrowserDialog1.SelectedPath, "*.txt", SearchOption.AllDirectories);
                scanProgress.Maximum = search.Length;
                foreach (string item in search)
                {
                    try
                    {
                        StreamReader stream = new StreamReader(item);
                        string read = stream.ReadToEnd();
                        string[] match = new string[] { "match" };
                        foreach (string st in match)
                        {
                            if (Regex.IsMatch(read, st))
                            {

                                matches++;
                                lbldetected.Text = "Matches: " + matches.ToString();
                                liDetected.Items.Add(item);
                            }
                            scanProgress.Increment(1);

                            if (scanProgress.Value == search.Length & matches > 0)
                            {
                                MessageBox.Show("Matches detected!");
                            }
                            else
                                if (scanProgress.Value == search.Length & matches == 0)
                                {
                                    MessageBox.Show("No match detected!");
                                }

                        }

                    }
                    catch (System.Exception excpt)
                    {
                        MessageBox.Show("Error", "Error Occurred");
                    }

                }

            }
            catch (System.Exception excpt)
            {
                MessageBox.Show("Select a folder to scan!", "Error Occurred");
            }
        }



So at the moment I have it scanning text files as a foundation to build around. Its simply only detecting the string "match". I kinda suffer mental blocks when it comes to programming but hopefully with practice I can start to see the solution a bit clearer. I know the code probably isn't very elegant nor the best way of doing things, but it works at the moment and if I can get it md5 hashing the files and matching I will be most happy :)

Thanks

Is This A Good Question/Topic? 0
  • +

Page 1 of 1