一.文件复制例子如下,具体情况,根据需求扩展。
/// <summary>
///
/// </summary>
/// <param name="srcFolder">源目录</param>
/// <param name="destFolder">目标目录</param>
/// <param name="filename">源文件名</param>
public static string ImageCopty(string srcFolder, string destFolder, string filename)
{
DirectoryInfo directoryInfo = new DirectoryInfo(srcFolder);
FileInfo[] files = directoryInfo.GetFiles();
string imageName = "";
foreach (FileInfo file in files) // Directory.GetFiles(srcFolder)
{
if (file.Name == filename) //file.Extension == ".doc"
{
imageName = Guid.NewGuid().ToString("N") + file.Extension; //把原来的图片名字换成GUID
file.CopyTo(Path.Combine(destFolder,imageName));
break;
}
//file.MoveTo(Path.Combine(destFolder, file.Name));
}
return imageName;
}
原文地址:https://www.cnblogs.com/zylstu/p/11875589.html