IO Directory DirectoryInfo
1.Directory和DirectoryInfo这两个类都是对文件进行操作,但Directory是静态类,所以它的执行效率会更高一点。
2.对文件操作。我们可以这样认为,Directory和directoryInfo都是一样的,只是表现形式不一样。
3.获取目录的文件名称或者是文件夹名称。
代码如下;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 string path = @"c:\wtqCreate";
2 string pathTxt = path + @"\my.txt";
3 if (!Directory.Exists(path))
4 {
5
6 Directory.CreateDirectory(path);
7 using (StreamWriter sw = File.CreateText(pathTxt))
8 {
9 sw.WriteLine("my name is wtq");
10 sw.WriteLine("and what's your name");
11 sw.WriteLine("my name is wwttqq");
12 sw.WriteLine("I Can do everyThing");
13 }
14 }
15 DirectoryInfo di = new DirectoryInfo(path);
16 var fp = di.GetFileSystemInfos();
17 foreach(var f in fp)
18 {
19 Console.WriteLine("简称{0},全名{1}",f.Name,f.FullName);
20 }
21
22 var dp = Directory.GetFileSystemEntries(path);
23 foreach (var item in dp)
24 {
25 Console.WriteLine("获取目录中的文件夹和文件的名称");
26 Console.WriteLine(item);
27 }
28 Console.ReadLine();
2 string pathTxt = path + @"\my.txt";
3 if (!Directory.Exists(path))
4 {
5
6 Directory.CreateDirectory(path);
7 using (StreamWriter sw = File.CreateText(pathTxt))
8 {
9 sw.WriteLine("my name is wtq");
10 sw.WriteLine("and what's your name");
11 sw.WriteLine("my name is wwttqq");
12 sw.WriteLine("I Can do everyThing");
13 }
14 }
15 DirectoryInfo di = new DirectoryInfo(path);
16 var fp = di.GetFileSystemInfos();
17 foreach(var f in fp)
18 {
19 Console.WriteLine("简称{0},全名{1}",f.Name,f.FullName);
20 }
21
22 var dp = Directory.GetFileSystemEntries(path);
23 foreach (var item in dp)
24 {
25 Console.WriteLine("获取目录中的文件夹和文件的名称");
26 Console.WriteLine(item);
27 }
28 Console.ReadLine();