using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication8 { //directory //directoryinfo //path //file class ExceptionTest1 { static void Main(string[] args) { //创建目录 Directory.CreateDirectory(@"/temp"); //删除目录 //Directory.Delete(@"/temp"); //判断该文件是否存在 Console.WriteLine(Directory.Exists(@"/temp")) ; //获得创建时间 Console.WriteLine(Directory.GetCreationTime(@"/temp")); //获得协调世界时 Console.WriteLine(Directory.GetCreationTimeUtc(@"/temp")); //获得应用程序的当前工作目录 // Console.WriteLine(Directory.GetCurrentDirectory()); //获得指定文件夹的子文件夹的详细目录 string[] dir = Directory.GetDirectories(@"/python"); foreach (string item in dir) { Console.WriteLine(item); } //获得符合指定通配符的子文件夹的详细信息 string[] dirs = Directory.GetDirectories(@"/python","*meta"); Console.WriteLine("*****************"); foreach (string item in dirs) { Console.WriteLine(item); } //返回路径的跟信息,卷信息 string root = Directory.GetDirectoryRoot(@"/temp"); Console.WriteLine("root "+root); //返回指定文件夹中子文件的文件名 string[] names = Directory.GetFiles(@"/jdk"); foreach (string item in names) { Console.WriteLine(item+" *"); } //获得最后访问时间 DateTime dt = Directory.GetLastAccessTime(@"/jdk"); Console.WriteLine(dt); //返回上次写入文件或目录的时间 DateTime dts = Directory.GetLastWriteTime(@"/jdk"); Console.WriteLine(dts); //获得此计算机的盘符 string[] pan = Directory.GetLogicalDrives(); foreach (string item in pan) { Console.WriteLine(item); } //返回制定目录的父目录 DirectoryInfo pathpa = Directory.GetParent(@"/jdk"); Console.WriteLine(pathpa.FullName+"***"); //改名或移动 Directory.Move(@"/tem", @"/temp"); DateTime dt2 = new DateTime(2018,1,1); // Directory.SetLastAccessTime(dt2); } } }