VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程C#使用Directoryinfo类获得目录信息和属性的方

本文实例讲述了C#使用Directoryinfo类获得目录信息和属性的方法。分享给大家供大家参考。具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.IO;
class MainClass {
  static void Main(string[] args) {
    FileInfo file = new FileInfo("c:\\a.txt");
    // Display directory information.
    DirectoryInfo dir = file.Directory;
    Console.WriteLine("Checking directory: " + dir.Name);
    Console.WriteLine("In directory: " + dir.Name);
    Console.Write("Directory exists: ");
    Console.WriteLine(dir.Exists.ToString());
    if (dir.Exists) {
      Console.Write("Directory created: ");
      Console.WriteLine(dir.CreationTime.ToString());
      Console.Write("Directory last updated: ");
      Console.WriteLine(dir.LastWriteTime.ToString());
      Console.Write("Directory last accessed: ");
      Console.WriteLine(dir.LastAccessTime.ToString());
      Console.Write("Directory attribute list: ");
      Console.WriteLine(dir.Attributes.ToString());
      Console.WriteLine("Directory contains: " +
        dir.GetFiles().Length.ToString() + " files");
    }
    Console.WriteLine();
  }
}

希望本文所述对大家的C#程序设计有所帮助。


相关教程