C#编程-115:文件夹操作之移动
彭世瑜 发布时间:2017-08-12 11:41:52 ,浏览量:3
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
-
- namespace MoveDerictoryTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- string pathSource = @"C:\Users\pengshiyu\Desktop\source\test";
- string pathDestination = @"C:\Users\pengshiyu\Desktop\destination\test";
-
- //先判断源文件夹是否存在
- if (Directory.Exists(pathSource))
- {
- try
- {
- //如果目标文件夹存在则会抛出异常
- Directory.Move(pathSource, pathDestination);
- Console.WriteLine("文件夹移动成功");
- }
- catch (Exception ex)
- {
-
- Console.WriteLine("文件夹移动失败:" + ex.Message);
- }
- }
- else
- {
- Console.WriteLine("文件夹不存在");
- }
- Console.ReadKey();
- }
-
- }
- }
1665367115
查看更多评论