/// <summary>
/// 拷贝文件,返回新文件路径及文件名,同名的不同文件加后缀(1)
/// </summary>
/// <param name="sourceFileName"></param>
/// <param name="destFileName"></param>
/// <returns></returns>
private string GetCopyPathFileName(string sourceFileName, string destFileName)
{
string sourceFileMD5 = Encrypt.GetMD5HashFromFile(sourceFileName);
string directory = Path.GetDirectoryName(destFileName);
string filename = Path.GetFileNameWithoutExtension(destFileName);
string extension = Path.GetExtension(destFileName);
int counter = 1;
string newFullPath = destFileName;
while (System.IO.File.Exists(newFullPath) && Encrypt.GetMD5HashFromFile(newFullPath) != sourceFileMD5)
{
string newFilename = filename + "(" + counter + ")" + extension;
newFullPath = Path.Combine(directory, newFilename);
counter++;
}
if (!File.Exists(newFullPath))
{
File.Copy(sourceFileName, newFullPath);
}
return newFullPath;
}
发表评论 取消回复