Is Equal for two path - CSharp System.IO

CSharp examples for System.IO:File Path

Description

Is Equal for two path

Demo Code


using System.Text;
using System.Linq;
using System.IO;/*from  w  w  w  .  j  a  va  2  s . c  o  m*/
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections;
using System;

public class Main{
        public static bool IsEqual(string strPath1, string strPath2)
        {
            if (String.IsNullOrEmpty(strPath1) == true
                && String.IsNullOrEmpty(strPath2) == true)
                return true;

            if (String.IsNullOrEmpty(strPath1) == true)
                return false;

            if (String.IsNullOrEmpty(strPath2) == true)
                return false;

            if (strPath1 == strPath2)
                return true;

            FileSystemInfo fi1 = new DirectoryInfo(strPath1);
            FileSystemInfo fi2 = new DirectoryInfo(strPath2);

            string strNewPath1 = fi1.FullName.ToUpper();
            string strNewPath2 = fi2.FullName.ToUpper();

            if (strNewPath1.Length != 0)
            {
                if (strNewPath1[strNewPath1.Length - 1] != '\\')
                    strNewPath1 += "\\";
            }
            if (strNewPath2.Length != 0)
            {
                if (strNewPath2[strNewPath2.Length - 1] != '\\')
                    strNewPath2 += "\\";
            }

            if (strNewPath1.Length != strNewPath2.Length)
                return false;

            if (strNewPath1 == strNewPath2)
                return true;

            return false;
        }
}

Related Tutorials