zoukankan      html  css  js  c++  java
  • .net BCL获取所有磁盘的信息

        获取所有磁盘的信息,以前在WIN32下,我们可以使用API来获取,现在我们使用.net的基类库来实现。看代码:

       1:         [Test]
       2:          public void DisplayAllDriveInfo()
       3:          {
       4:              DriveInfo.GetDrives().ToList().ForEach(drive =>
       5:              {
       6:                  if (drive != null)
       7:                      if (drive.IsReady)
       8:                      {
       9:                          Console.WriteLine("Drive " + drive.Name + " is ready.");
      10:                          Console.WriteLine("AvailableFreeSpace: " + drive.AvailableFreeSpace);
      11:                          Console.WriteLine("DriveFormat: " + drive.DriveFormat);
      12:                          Console.WriteLine("DriveType: " + drive.DriveType);
      13:                          Console.WriteLine("Name: " + drive.Name);
      14:                          Console.WriteLine("RootDirectory.FullName: " + drive.RootDirectory.FullName);
      15:                          Console.WriteLine("TotalFreeSpace: " + drive.TotalFreeSpace);
      16:                          Console.WriteLine("TotalSize: " + drive.TotalSize);
      17:                          Console.WriteLine("VolumeLabel: " + drive.VolumeLabel);
      18:                      }
      19:                      else
      20:                          Console.WriteLine("Drive " + drive.Name + " is not ready.");
      21:              }
      22:              );
      23:          }

         将输出:

    Drive C:\ is ready.
    AvailableFreeSpace: 1386864640
    DriveFormat: NTFS
    DriveType: Fixed
    Name: C:\
    RootDirectory.FullName: C:\
    TotalFreeSpace: 1386864640
    TotalSize: 11400204288
    VolumeLabel:
    Drive D:\ is ready.
    AvailableFreeSpace: 3914825728
    DriveFormat: NTFS
    DriveType: Fixed
    Name: D:\
    RootDirectory.FullName: D:\
    TotalFreeSpace: 3914825728
    TotalSize: 21476171776
    VolumeLabel: Programme
    Drive E:\ is ready.
    AvailableFreeSpace: 601378816
    DriveFormat: NTFS
    DriveType: Fixed
    Name: E:\
    RootDirectory.FullName: E:\
    TotalFreeSpace: 601378816
    TotalSize: 21476171776
    VolumeLabel: Development
    Drive F:\ is ready.
    AvailableFreeSpace: 549265408
    DriveFormat: NTFS
    DriveType: Fixed
    Name: F:\
    RootDirectory.FullName: F:\
    TotalFreeSpace: 549265408
    TotalSize: 33411051520
    VolumeLabel: Recourse
    Drive G:\ is ready.
    AvailableFreeSpace: 90664960
    DriveFormat: NTFS
    DriveType: Fixed
    Name: G:\
    RootDirectory.FullName: G:\
    TotalFreeSpace: 90664960
    TotalSize: 20966203392
    VolumeLabel: Entertainment
    Drive H:\ is ready.
    AvailableFreeSpace: 1181413376
    DriveFormat: NTFS
    DriveType: Fixed
    Name: H:\
    RootDirectory.FullName: H:\
    TotalFreeSpace: 1181413376
    TotalSize: 11301498880
    VolumeLabel: Work
    Drive I:\ is not ready.
    Drive J:\ is not ready。


    作者:Petter Liu
    出处:http://www.cnblogs.com/wintersun/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    该文章也同时发布在我的独立博客中-Petter Liu Blog

  • 相关阅读:
    sh_04_第1个函数改造
    sh_03_第1个函数
    sh_02_快速体验
    sh_01_九九乘法表
    11_测试模块
    sh_12_转义字符
    sh_11_九九乘法表
    sh_10_嵌套打印小星星
    Mariadb/Redis数据库
    部署django项目
  • 原文地址:https://www.cnblogs.com/wintersun/p/1779413.html
Copyright © 2011-2022 走看看