C# 计算文件重复时,文件名后面加(1) ,(2)

  string name = "sfg.v(1)(2).jpg";
            Match match = Regex.Match(name,@"^(.*)?(\..*)$");
            if(match.Success)
            {
                Match match1 = Regex.Match(match.Groups[1].Value, @"^(.*)?\(([0-9]+)\)$");
                if (match1.Success)
                {
                    name = string.Format("{0}({1}){2}", match1.Groups[1].Value, Convert.ToInt64(match1.Groups[2].Value) + 1, match.Groups[2].Value);
                }
                else
                {
                    name = string.Format("{0}(1){1}", match.Groups[1].Value, match.Groups[2].Value);
                }
            }

 

posted @ 2014-08-30 10:01  metoer  阅读(871)  评论(0编辑  收藏  举报