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

  • 相关阅读:
    ES6之6种遍历对象属性的方法
    css自定义滚动条样式,自定义文字选择样式,设置文字不被选择
    js img转换base64
    移动端rem造成的很多问题
    移动端边框1像素的问题
    【小练习1】如何制作“表单”
    2015-09-24 第六节课 (CSS补充和html 标签讲解、浏览器兼容性)
    2015-09-22 第四节课 CSS块级元素 行内元素 浮动 盒子模型 绝对定位、相当定位和固定定位
    2015-09-21 第三节课 css属性 border(边框)、background(背景)
    html你可能还不知道的一些知识点
  • 原文地址:https://www.cnblogs.com/wintersun/p/1779413.html
Copyright © 2011-2022 走看看