System.IO.DriveInfo.GetDrives


Imports System.Text
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sb As New StringBuilder()
        Dim M As Double
        '建立stringbuilder对象,用于在内存中存储临时信息
        Dim myAllDrives As DriveInfo() = DriveInfo.GetDrives()
        ' DriveInfo对象数组,存储获得的磁盘信息
        Try
            For Each myDrive As DriveInfo In myAllDrives
                '循环写入每个磁盘的参数 属性
                If myDrive.IsReady Then
                    sb.Append("磁盘驱动器盘符:")
                    sb.AppendLine(myDrive.Name)
                    sb.Append("磁盘卷标:")
                    sb.AppendLine(myDrive.VolumeLabel)
                    sb.Append("磁盘类型:")
                    sb.AppendLine(myDrive.DriveType.ToString())
                    sb.Append("磁盘格式:")
                    sb.AppendLine(myDrive.DriveFormat)
                    sb.Append("磁盘大小:")
                    m = myDrive.TotalSize / (1024 * 1024)
                    sb.AppendLine(m.ToString() + "M")
                    sb.Append("磁盘可用剩余空间:")
                    m = myDrive.AvailableFreeSpace / (1024 * 1024)
                    sb.AppendLine(m.ToString() + "M")
                    sb.Append("磁盘总剩余空间:")
                    m = myDrive.TotalFreeSpace / (1024 * 1024)
                    sb.AppendLine(m.ToString() + "M")
                    sb.AppendLine("--------------------------------------------------")
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Me.TextBox1.Text = sb.ToString()
        '显示信息
    End Sub
End Class



System.IO.Path 文件名、路径、扩展名 处理



欢迎关注微信公众账号ByCAD