首页 > 代码库 > C# 保存文件如有重名在原名后加(*)

C# 保存文件如有重名在原名后加(*)

C#保存文件如有重名加() **(1)

      private string GetNewPathForDupes(string path)        {            string directory = Path.GetDirectoryName(path);            string filename = Path.GetFileNameWithoutExtension(path);            string extension = Path.GetExtension(path);            int counter = 1;            string newFullPath;            do            {                //string newFilename = "{0}({1}).{2}".FormatWith(filename, counter, extension);                string newFilename = string.Format("{0}({1}).{2}", filename, counter, extension);                newFullPath = Path.Combine(directory, newFilename);                counter++;            } while (System.IO.File.Exists(newFullPath));            return newFullPath;        }

 

C# 保存文件如有重名在原名后加(*)