none
获取磁盘信息 RRS feed

  • 问题

  • 于请高手指点:如何用VB.NET获取与本地磁盘相关的信息,比如说,磁盘类型、卷标、已用空间、可用空间等等…… 望不吝赐教,先行谢过!
    2011年5月20日 0:17

答案

  • 你好

    或者你可以嘗試使用DRIVEINFO 這個類

    E.G.

    Imports System
    Imports System.IO
    
    Class Test
      Public Shared Sub Main()
        Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
    
        Dim d As DriveInfo
        For Each d In allDrives
          Console.WriteLine("Drive {0}", d.Name)
          Console.WriteLine(" File type: {0}", d.DriveType)
          If d.IsReady = True Then
            Console.WriteLine(" Volume label: {0}", d.VolumeLabel)
            Console.WriteLine(" File system: {0}", d.DriveFormat)
            Console.WriteLine( _
              " Available space to current user:{0, 15} bytes", _
              d.AvailableFreeSpace)
    
            Console.WriteLine( _
              " Total available space:     {0, 15} bytes", _
              d.TotalFreeSpace)
    
            Console.WriteLine( _
              " Total size of drive:      {0, 15} bytes ", _
              d.TotalSize)
          End If
        Next
      End Sub
    End Class
    'This code produces output similar to the following:
    '
    'Drive A:\
    ' File type: Removable
    'Drive C:\
    ' File type: Fixed
    ' Volume label: 
    ' File system: FAT32
    ' Available space to current user:   4770430976 bytes
    ' Total available space:        4770430976 bytes
    ' Total size of drive:        10731683840 bytes 
    'Drive D:\
    ' File type: Fixed
    ' Volume label: 
    ' File system: NTFS
    ' Available space to current user:  15114977280 bytes
    ' Total available space:       15114977280 bytes
    ' Total size of drive:        25958948864 bytes 
    'Drive E:\
    ' File type: CDRom
    '
    'The actual output of this code will vary based on machine and the permissions
    'granted to the user executing it.
    

    詳情可以參考以下URL

    http://msdn.microsoft.com/zh-cn/library/system.io.driveinfo.aspx

    Please correct me if my concept is wrong


    Chi
    • 已建议为答案 小歐ouMVP 2011年5月20日 6:48
    • 已标记为答案 CXJust 2011年5月22日 8:50
    2011年5月20日 5:10
    版主

全部回复

  • 你好

    或者你可以嘗試使用DRIVEINFO 這個類

    E.G.

    Imports System
    Imports System.IO
    
    Class Test
      Public Shared Sub Main()
        Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
    
        Dim d As DriveInfo
        For Each d In allDrives
          Console.WriteLine("Drive {0}", d.Name)
          Console.WriteLine(" File type: {0}", d.DriveType)
          If d.IsReady = True Then
            Console.WriteLine(" Volume label: {0}", d.VolumeLabel)
            Console.WriteLine(" File system: {0}", d.DriveFormat)
            Console.WriteLine( _
              " Available space to current user:{0, 15} bytes", _
              d.AvailableFreeSpace)
    
            Console.WriteLine( _
              " Total available space:     {0, 15} bytes", _
              d.TotalFreeSpace)
    
            Console.WriteLine( _
              " Total size of drive:      {0, 15} bytes ", _
              d.TotalSize)
          End If
        Next
      End Sub
    End Class
    'This code produces output similar to the following:
    '
    'Drive A:\
    ' File type: Removable
    'Drive C:\
    ' File type: Fixed
    ' Volume label: 
    ' File system: FAT32
    ' Available space to current user:   4770430976 bytes
    ' Total available space:        4770430976 bytes
    ' Total size of drive:        10731683840 bytes 
    'Drive D:\
    ' File type: Fixed
    ' Volume label: 
    ' File system: NTFS
    ' Available space to current user:  15114977280 bytes
    ' Total available space:       15114977280 bytes
    ' Total size of drive:        25958948864 bytes 
    'Drive E:\
    ' File type: CDRom
    '
    'The actual output of this code will vary based on machine and the permissions
    'granted to the user executing it.
    

    詳情可以參考以下URL

    http://msdn.microsoft.com/zh-cn/library/system.io.driveinfo.aspx

    Please correct me if my concept is wrong


    Chi
    • 已建议为答案 小歐ouMVP 2011年5月20日 6:48
    • 已标记为答案 CXJust 2011年5月22日 8:50
    2011年5月20日 5:10
    版主
  • 高手之道,见多识广。众里寻她千百度,暮然回首,竟在灯火阑姗处。非常之感谢!
    2011年5月22日 8:54
  • 谢谢高手。
    Be a good forum member. Make this forum a great place to meet and interact with others around the world.
    2011年5月22日 15:58