File类的Move方法可以移动文件,使用格式如下:
Move(string sourceFileName,string desfFileName)//第一个参数是源文件,第二个参数是目标文件
移动文件时可能存在下面三种情况
1)、源文件存在,目标文件不存在。
2)、源文件存在、目标文件存在。
3)、源文件不存在。
代码如下:
string pathSource = @"C:\Users\Administrator\Desktop\Source\steng.cn.txt";
string pathDestination = @"C:\Users\Administrator\Desktop\Destination\copy.txt";
if (File.Exists(pathSource))//源文件存在
{
try
{
if (File.Exists(pathDestination))//目标文件已存在
{
Console.WriteLine("文件移动失败,该处有同名文件");
}
else
{
File.Move(pathSource, pathDestination);
Console.WriteLine("文件移动成功");
}
}
catch(Exception ex)
{
Console.WriteLine("移动文件出错,原因是:" + ex.Message.ToString());
}
}
else
{
Console.WriteLine("源文件不存在,无法移动!");
}
Console.ReadKey();
站内文章:均为188bet博彩体育app下载方式
各部门原创内容如需转载请著名本文网站链接://www.mcissock.com/new/27280.html未经允许转载要受法律责任,如需转载请联系269247937@qq.com
本文链接://www.mcissock.com/new/27280.html
tags:
郑州网站建设郑州网站制作郑州网站设计郑州建站公司郑州网站优化郑州做网站郑州小程序开发郑州网络公司