您的位置:首页 > 其它

LocalDriveInfo

2008-11-07 13:52 85 查看
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 {

static void Main(string[] args)

{

string[] drives = System.Environment.GetLogicalDrives();

DriveInfo driveInfo = null;

System.Console.WriteLine(GetOperationSystemInName());

System.Console.WriteLine("卷标 盘符 类型 文件系统 总大小(byte) 可用空间大小(byte)");

for (int i = 0; i < drives.Length; i++)

{

driveInfo = new DriveInfo(drives[i]);

if (driveInfo.IsReady)

{

System.Console.WriteLine("{0} {1} {2} {3} {4} {5}", driveInfo.VolumeLabel, driveInfo.Name,

driveInfo.DriveType, driveInfo.DriveFormat, driveInfo.TotalSize.ToString("###,###") /**//*/ (1024 * 1024)*/, driveInfo.AvailableFreeSpace.ToString("###,###") /**//*/ (1024*1024))*/);

}

else

{

System.Console.WriteLine("{0} {1} {2} {3} {4} {5}", "", driveInfo.Name,

driveInfo.DriveType, "", "", "", "");

}

}

System.Console.ReadLine();

}

/**///// <summary>

/// 获取系统名称

/// </summary>

/// <returns></returns>

public static string GetOperationSystemInName()

{

OperatingSystem os = System.Environment.OSVersion;

string osName = "UNKNOWN";

switch (os.Platform)

{

case PlatformID.Win32Windows:

switch (os.Version.Minor)

{

case 0: osName = "Windows 95"; break;

case 10: osName = "Windows 98"; break;

case 90: osName = "Windows ME"; break;

}

break;

case PlatformID.Win32NT:

switch (os.Version.Major)

{

case 3: osName = "Windws NT 3.51"; break;

case 4: osName = "Windows NT 4"; break;

case 5: if (os.Version.Minor == 0)

{

osName = "Windows 2000";

}

else if (os.Version.Minor == 1)

{

osName = "Windows XP";

}

else if (os.Version.Minor == 2)

{

osName = "Windows Server 2003";

}

break;

case 6: osName = "Longhorn"; break;

}

break;

}

return String.Format("{0},{1}", osName, os.Version.ToString());

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: