获取硬盘空间 [英] Getting Hard Drive Space

查看:91
本文介绍了获取硬盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我找到了以下代码:

Hi ive found this code:

Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
       (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToMe As Long, _
       ByRef lpTotalNumberOfBytes As Long, ByRef lpTotalNumberOfFreeBytes As Long) As Integer




   Private Sub Button1_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles Button1.Click

       'drive name or folder path
       Dim DriveOrFolder As String = "c:"

       Dim FreeBytesAvailableToMe As Long 'the available free bytes to the user whose process this is
       Dim TotalBytes As Long 'the total available bytes to the user whose process this is
       Dim FreeBytes As Long 'the total number of free bytes on a disk

       Dim FetchResult As Integer

       'the function returns non zero if successful and 0 if failed
       FetchResult = GetDiskFreeSpaceEx(DriveOrFolder, FreeBytesAvailableToMe, _
            TotalBytes, FreeBytes)

       If FetchResult <> 0 Then

           Dim bytes As String = Format(FreeBytes, "###,###,##") & " bytes )"


           'convert to Megabytes
           Dim megabytes As String
           Dim MBytes As Double
           MBytes = (FreeBytes \ 1024) \ 1024
           megabytes = Format(MBytes, "###,###,##") & " MB free"

           MessageBox.Show(megabytes & " (" & bytes)

       Else

           MessageBox.Show("Drive not available or folder not accessible")

       End If

   End Sub


################################################ ############################


##############################################################################
How would i get it to read all the HDD?

推荐答案

使用

此处是如何实现此目标的路线图.我会把细节留给您找出来,因为您将从中学到很多.如果您还有其他后续问题,请随时添加.干杯.

代码中的这一行定义了将要分析的驱动器. Dim DriveOrFolder As String = "c:"
在您拥有的分析方法周围创建一个循环,该循环将所有驱动器值一次作为参数提供.
Here is a road map of how you can do this. I''ll leave the details to you to figure out because you will learn the most from that. If you have any other follow up questions, then feel free to add them. Cheers.

This line in the code defines the drive that will be analyzed. Dim DriveOrFolder As String = "c:"
Create a loop around the analysis method that you have that will feed all the drive values in one at a time as an argument.
Private Function GetDiskFreeSpace(DriveOrFolder As String)
... ' Put the internal method code here, but instead of showing the result in a message box, return the MBytes variable.
End Function

Private Sub Button1_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles Button1.Click

   Dim arDrives() As String
   arDrives = Directory.GetLogicalDrives()

   'Loop through all the logical drives and make a call to the GetDiskFreeSpace function for each one.
   'Store the values returned in each call to a dictionary object.

   'Display your results however you wish.
End Sub


这篇关于获取硬盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆