⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diskinfo.bas

📁 常用基本函数库,也许你需要的正在其中!如果不做程序
💻 BAS
字号:
Attribute VB_Name = "MODDiskInfo"
Option Explicit
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, _
lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, _
lpTotalNumberOfClusters As Long) As Long

Type DISKSPACEINFO
    RootPath As String * 3
    FreeBytes As Long
    TotalBytes As Long
    FreePcnt As Single
    UsedPcnt As Single
End Type
Global CurrentDisk As DISKSPACEINFO

Function GetDiskInfo(sRootPathName As String, sWhatInfo As String) As String
    'TO USE THIS FUNCTION:
    'INFO Options (Second Parameter):
    'FreeBytes, TotalBytes, FreePcnt, or UsedPcnt
    'Dim sMyInfo As String
    'sMyInfo = GetDiskInfo("c:\", "FreeBytes")
    Dim X As Long
    Dim lSectorsPerCluster As Long, lBytesPerSector As Long
    Dim lNumberOfFreeClusters As Long, lTotalNumberOfClusters As Long
    X = GetDiskFreeSpace(sRootPathName, lSectorsPerCluster, lBytesPerSector, lNumberOfFreeClusters, lTotalNumberOfClusters)
    GetDiskInfo = X
    If X Then
        CurrentDisk.RootPath = sRootPathName
        CurrentDisk.FreeBytes = lBytesPerSector * lSectorsPerCluster * lNumberOfFreeClusters
        CurrentDisk.TotalBytes = lBytesPerSector * lSectorsPerCluster * lTotalNumberOfClusters
        CurrentDisk.FreePcnt = (CurrentDisk.TotalBytes - CurrentDisk.FreeBytes) / CurrentDisk.TotalBytes
        CurrentDisk.UsedPcnt = CurrentDisk.FreeBytes / CurrentDisk.TotalBytes
    Else
        CurrentDisk.RootPath = ""
        CurrentDisk.FreeBytes = 0
        CurrentDisk.TotalBytes = 0
        CurrentDisk.FreePcnt = 0
        CurrentDisk.UsedPcnt = 0
    End If
    Select Case UCase(sWhatInfo)
        Case "ROOTPATH"
            GetDiskInfo = CurrentDisk.RootPath
        Case "FREEBYTES"
            GetDiskInfo = Format$(CurrentDisk.FreeBytes, "###,###,##0")
        Case "TOTALBYTES"
            GetDiskInfo = Format$(CurrentDisk.TotalBytes, "###,###,##0")
        Case "FREEPCNT"
            GetDiskInfo = Format$(CurrentDisk.FreePcnt, "Percent")
        Case "USEDPCNT"
            GetDiskInfo = Format$(CurrentDisk.UsedPcnt, "Percent")
    End Select
End Function
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -