LocalDriveInfo

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 using System.IO;
 5 
 6 namespace LocalDriveInfo
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             string[] drives = System.Environment.GetLogicalDrives();
13             DriveInfo driveInfo = null;
14             System.Console.WriteLine(GetOperationSystemInName());
15             System.Console.WriteLine("卷标 盘符 类型 文件系统 总大小(byte) 可用空间大小(byte)");
16             for (int i = 0; i < drives.Length; i++)
17             {
18                 driveInfo = new DriveInfo(drives[i]);
19                 if (driveInfo.IsReady)
20                 {
21                     System.Console.WriteLine("{0} {1} {2} {3} {4} {5}", driveInfo.VolumeLabel, driveInfo.Name,
22                         driveInfo.DriveType, driveInfo.DriveFormat, driveInfo.TotalSize.ToString("###,###"/**//*/ (1024 * 1024)*/, driveInfo.AvailableFreeSpace.ToString("###,###"/**//*/ (1024*1024))*/);
23                 }
24                 else
25                 {
26                     System.Console.WriteLine("{0} {1} {2} {3} {4} {5}""", driveInfo.Name,
27                         driveInfo.DriveType, """""""");
28                 }
29             }
30             System.Console.ReadLine();
31         }
32 
33         /**////<summary>
34         /// 获取系统名称
35         /// </summary>
36         /// <returns></returns>
37         public static string GetOperationSystemInName()
38         {
39             OperatingSystem os = System.Environment.OSVersion;
40             string osName = "UNKNOWN";
41             switch (os.Platform)
42            {
43                 case PlatformID.Win32Windows:
44                     switch (os.Version.Minor)
45                    {
46                         case 0: osName = "Windows 95"break;
47                         case 10: osName = "Windows 98"break;
48                         case 90: osName = "Windows ME"break;
49                     }
50                     break;
51                 case PlatformID.Win32NT:
52                     switch (os.Version.Major)
53                     {
54                         case 3: osName = "Windws NT 3.51"break;
55                         case 4: osName = "Windows NT 4"break;
56                         case 5if (os.Version.Minor == 0)
57                             {
58                                 osName = "Windows 2000";
59                             }
60                             else if (os.Version.Minor == 1)
61                             {
62                                 osName = "Windows XP";
63                             }
64                             else if (os.Version.Minor == 2)
65                             {
66                                 osName = "Windows Server 2003";
67                             }
68                             break;
69                         case 6: osName = "Longhorn"break;
70                     }
71                     break;
72             }
73             return String.Format("{0},{1}", osName, os.Version.ToString());
74         }
75     }
76 }
posted @ 2008-11-07 13:52  TONYBINLJ  阅读(254)  评论(0编辑  收藏  举报