ディスクの空き容量を取得(V)          <TOP>


SHGetDiskFreeSpace ディスクの空き容量を調べる

 

F-Basic では、Currencyが使えないので、ULARGE_INTEGER構造体でHigh、Lowに分けて取り出しています。

 

'================================================================
'= ディスクの空き容量を取得(V)
'=    (SHGetDiskFreeSpace.bas)
'================================================================
#include "Windows.bi"

Type ULARGE_INTEGER
    LowPart As Long
    HighPart As Long
End Type

' 指定のディレクトリを含むディスクの空き容量を調べる
Declare Function Api_SHGetDiskFreeSpace& Lib "Shell32" Alias "SHGetDiskFreeSpaceA" (ByVal pszVolume$, pqwFreeCaller As ULARGE_INTEGER, pqwTot As ULARGE_INTEGER, pqwFree As ULARGE_INTEGER)

#define vbCrLf (Chr$(13) & Chr$(10))    'キャリッジリターンとラインフィード(\r\n)

Var Shared Text1 As Object
Var Shared Button1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Function ULARGE_INTEGER_DOUBLE(ui As ULARGE_INTEGER) As Double
Function ULARGE_INTEGER_DOUBLE(ui As ULARGE_INTEGER) As Double
    Var lHigh As Long
    Var lLow As Long

    lHigh = ui.HighPart * 2
    lLow = ui.LowPart

    If lLow And (-2147483648) THen
        lHigh = lHigh + 1
    End If

    lLow = lLow And &H7FFFFFFF
    ULARGE_INTEGER_DOUBLE = lLow + lHigh * 2 ^ 31
End Function

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var Drive As String
    Var FreeCaller As ULARGE_INTEGER
    Var Total As ULARGE_INTEGER
    Var Free As ULARGE_INTEGER
    Var txt As String
    Var Ret As Long

    Drive = "C:\"

    Ret = Api_SHGetDiskFreeSpace(Drive, FreeCaller, Total, Free)

    txt = txt & "使用可能容量: " & Format$(ULARGE_INTEGER_DOUBLE(FreeCaller), "###,###,###,###") & vbCrLf
    txt = txt & "総  容  量: " & Format$(ULARGE_INTEGER_DOUBLE(Total)     , "###,###,###,###") & vbCrLf
    txt = txt & "空 き 容 量 : " & Format$(ULARGE_INTEGER_DOUBLE(Free)      , "###,###,###,###")
    Text1.SetWindowText txt
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End