int count = 1; //在重复名称后加(序号) while (File.Exists(path)) { if (path.Contains(").")) { int start = path.LastIndexOf("("); int end = path.LastIndexOf(").") - path.LastIndexOf("(") + 2; path = path.Replace(path.Substring(start, end), string.Format("({0}).", count)); } else { path = path.Replace(".", string.Format("({0}).", count)); } count++; }