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());
}
}
}
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());
}
}
}
相关文章推荐
- C# DriveInfo 读取驱动器出现的错误提示排除方法,原来超幼稚!
- DriveInfo.GetDrives使用错误备忘
- java.io.InvalidClassException: javax.management.MBeanAttributeInfo; local class incompatible:
- IntelliJ IDEA在Local模式下Spark程序消除日志中INFO输出
- Permission denied: '/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg/EGG-INFO/requires.txt
- info AI drive
- Installation Directory must be on a local hard drive解决办法
- 16-07-31 Cannot refer to the non-final local variable homePageInfo defined in an enclosing scope
- IntelliJ IDEA在Local模式下Spark程序消除日志中INFO输出
- 指定的参数错误。Vim.Host.DiskPartitionInfo.-spec VSPHERE.LOCAL\Administrator WIN-DOPGQVRRU2C
- DriveInfo类查看磁盘信息
- java.io.InvalidClassException: javax.management.MBeanAttributeInfo; local class incompatible:
- .NET System.IO.DriveInfo 分析,个人感觉M$有点废
- C#.NET GetLocalMachineInfo.cs
- IntelliJ IDEA Spark程序在Local模式下消除日志输出INFO信息
- Linux Apache 启动时错误httpd: apr_sockaddr_info_get() failed for host.localdomain解决记录
- Entire feature will be installed on local hard drive
- .NET System.IO.DriveInfo 分析,个人感觉M$有点废
- 請小心localpics.info,應該算是MSN病毒[轉]
- Local/Dictionary Managed DB info