目录包含关系比较

2015-10-16 10:44:10  访问(1425) 赞(0) 踩(0)


        /// <summary>
        /// 获得完整目录名(如果有\结尾,则过滤掉)
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string DirectoryFullNameGet(string str)
        {
            if (str == null || str.Length == 0)
                return "";

            DirectoryInfo info = new DirectoryInfo(str);

            string theResult = info.FullName;

            if (theResult.EndsWith("\\"))
                return theResult.Substring(0, theResult.Length - 1);

            return theResult;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="oneDir"></param>
        /// <param name="twoDir"></param>
        /// <returns></returns>
        public eKing.AutoUpdateApp.Enums.DirRelate.EmDirRelate EmDirRelateGet(string oneDir, string twoDir)
        {
            if (oneDir == null || oneDir.Length == 0 || oneDir.Trim().Length == 0)
            {

                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:"
                        + "传入的字符串参数:"
                        + "string oneDir"
                        + "为null或trim后为空。"
                    );
            }

            if (twoDir == null || twoDir.Length == 0 || twoDir.Trim().Length == 0)
            {
                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:"
                        + "传入的字符串参数:"
                        + "string twoDir"
                        + "为null或trim后为空。"
                    );
            }

            oneDir = DirectoryFullNameGet(oneDir).ToLower() + "\\";
            twoDir = DirectoryFullNameGet(twoDir).ToLower() + "\\";


            if (oneDir == twoDir)
                return eKing.AutoUpdateApp.Enums.DirRelate.EmDirRelate.相同;

            if (oneDir.StartsWith(twoDir))
                return eKing.AutoUpdateApp.Enums.DirRelate.EmDirRelate.A包含B;

            if (twoDir.StartsWith(oneDir))
                return eKing.AutoUpdateApp.Enums.DirRelate.EmDirRelate.B包含A;

            return eKing.AutoUpdateApp.Enums.DirRelate.EmDirRelate.不相同;
        }


标签:目录包含关系比较 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)