您当前的位置: 首页 >  c#

彭世瑜

暂无认证

  • 3浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#编程-115:文件夹操作之移动_彭世瑜_新浪博客

彭世瑜 发布时间:2017-08-12 11:41:52 ,浏览量:3

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace MoveDerictoryTest
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string pathSource = @"C:\Users\pengshiyu\Desktop\source\test";
  14.             string pathDestination = @"C:\Users\pengshiyu\Desktop\destination\test";
  15.  
  16.             //先判断源文件夹是否存在
  17.             if (Directory.Exists(pathSource))
  18.             {
  19.                 try
  20.                 {
  21.                     //如果目标文件夹存在则会抛出异常
  22.                     Directory.Move(pathSource, pathDestination);
  23.                     Console.WriteLine("文件夹移动成功");
  24.                 }
  25.                 catch (Exception ex)
  26.                 {
  27.  
  28.                     Console.WriteLine("文件夹移动失败:" + ex.Message);
  29.                 }
  30.             }
  31.             else
  32.             {
  33.                 Console.WriteLine("文件夹不存在");
  34.             }
  35.             Console.ReadKey();
  36.         }
  37.  
  38.     }
  39. }
C#编程-115:文件夹操作之移动
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0489s