C#文件操作之把一个文件复制到另外一个文件夹下

一.文件复制例子如下,具体情况,根据需求扩展。

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

C#文件操作之把一个文件复制到另外一个文件夹下

上一篇:七十五:flask.Restful之Restful.API介绍


下一篇:探索Android中的Parcel机制(下)