C# 文件复制和移动操作(单个文件)
string path = @"d:\EM1.txt";
string path2 = @"d:\云轩\EM2.txt";
FileInfo fi1 = new FileInfo(path);
FileInfo fi2 = new FileInfo(path2);
try
{
// Create the source file.
// using (FileStream fs = fi1.Create()) { }
//Ensure that the target file does not exist.
if (File.Exists(path2))
{
fi2.Delete();
}
//Copy the file.f
fi1.CopyTo(path2);
Console.WriteLine("{0} was copied to {1}.", path, path2);
}
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
}
原文链接:https://blog.csdn.net/sinat_40692412/article/details/85778410
C# 复制文件(文件夹)
string pLocalFilePath ="";//要复制的文件路径
string pSaveFilePath ="";//指定存储的路径
if (File.Exists(pLocalFilePath))//必须判断要复制的文件是否存在
{
File.Copy(pLocalFilePath, pSaveFilePath, true);//三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
}