2
Answers

Comparing two files

Photo of darma teja

darma teja

12y
1k
1
Hi,

I have two files.

In 1st file:

<?xml version="1.0" encoding="UTF-16"?>

<king version="4.0" ExtFileType="Extract">

<Header>

<FFD GUID="{F5C91E25-E904-4AD0-AA6A-41FD0A5A12E4}" Name=""/><SecureSeg level="no"/><HistoryOpt active="no"/>

<Header>



in 2nd file:

[FileVersion]

GUID={F5C91E25-E904-4AD0-AA6A-41FD0A5A12E4}

Version=9

MarkupVersion=0

DisplayName=XML-MDB-Satzweise-nxt

FileExtension=*.xml


How can i compare two files Based on GUID.  If these two GUID's are equal than two files are the same.

Thanks

Darma

Answers (2)

0
Photo of Vulpes
NA 98.3k 1.5m 12y
Assuming there's only one GUID in each file or it's just the first one you need to match, then this is easily done using a regular expression.

Here's some sample code:

using System;
using System.IO;
using System.Text.RegularExpressions;

class Test
{
   static void Main()
   {
      string regExp = 
      @"(?i)\b" +
      @"[0-9A-F]{8}-" +
      @"[0-9A-F]{4}-" +
      @"[0-9A-F]{4}-" +
      @"[0-9A-F]{4}-" +
      @"[0-9A-F]{12}" +
      @"\b";

      string text = File.ReadAllText("darma.xml");
      string guid = Regex.Match(text, regExp).Value;
      Console.WriteLine(guid);

      string text2 = File.ReadAllText("darma.ini");
      string guid2 = Regex.Match(text2, regExp).Value;
      Console.WriteLine(guid2);

      if (guid == guid2)
         Console.WriteLine("Files are the same");
      else
         Console.WriteLine("Files are not the same");
      Console.ReadKey();
   }
 
 


Accepted
0
Photo of darma teja
NA 493 194.3k 12y
Wonderful!!!

Thanks allot!!!