C#文件操作之把一个文件复制到另外一个文件夹下
2021-01-29 00:14
标签:gui public filename inf uid 文件夹 static rect param 一.文件复制例子如下,具体情况,根据需求扩展。 /// C#文件操作之把一个文件复制到另外一个文件夹下 标签:gui public filename inf uid 文件夹 static rect param 原文地址:https://www.cnblogs.com/zylstu/p/11875589.html
///
///
/// 源目录
/// 目标目录
/// 源文件名
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;
}
下一篇:两个窗体通过委托来传值