private void button1_Click(object sender, EventArgs e)
{try{//创建主测试文件夹Directory.CreateDirectory(@".\TestDirectory");//创建待剪切测试文件夹Directory.CreateDirectory(@".\MoveDirectory");//将待剪切测试文件夹,剪切到主测试文件夹中Directory.Move(@".\MoveDirectory", @".\TestDirectory\MoveDirectory");Console.WriteLine("文件夹剪切完成");//用来存储,获取到的文件夹中的各种路径string[] paths = null;//获取路径下的文件夹paths = Directory.GetDirectories(@".\","*.*");foreach(string path in paths){Console.WriteLine(path);}Console.WriteLine("----------------------------");//获取路径下的文件paths =Directory.GetFiles(@".\", "*.*");foreach (string path in paths){Console.WriteLine(path);}Console.WriteLine("----------------------------");//获取路径下的文件系统paths =Directory.GetFileSystemEntries(@".\", "*.*");foreach (string path in paths){Console.WriteLine(path);}Console.WriteLine("----------------------------");//用来表示文件夹是否存在bool isExists = false;//未删除前文件夹存在isExists=Directory.Exists(@".\TestDirectory");Console.WriteLine("文件存在的状态为:{0}",isExists);Console.WriteLine("----------------------------");//删除路径下的文件夹Directory.Delete(@".\TestDirectory",true);Console.WriteLine("删除文件完成");Console.WriteLine("----------------------------");//删除后文件夹不存在isExists =Directory.Exists(@".\TestDirectory");Console.WriteLine("文件存在的状态为:{0}", isExists);Console.WriteLine("----------------------------");} catch{Console.WriteLine("KaiError:{0}",e.ToString());Console.WriteLine("----------------------------");}finally{Console.WriteLine("结束");}
}