/// <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;
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部