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(); } } }