全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:15617636856

郑州网站建设

当前位置: 首页 > 新闻资讯>>文件操作之移动文件

文件操作之移动文件

作者:郑州网络公司发布时间:2023-09-14 16:15:40查看次数:来源:网络

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:郑州网站建设郑州网站制作郑州网站设计郑州建站公司郑州网站优化郑州做网站郑州小程序开发郑州网络公司
网页是否收录:
返回目录 在线咨询

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。

  • 返回顶部
  • 15617636856
  • QQ在线
  • 微信二维码
0
Baidu
map