메뉴 건너뛰기

Dev tips

http://mwultong.blogspot.com/2006/05/vbscript-vbs.html''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'                                                        DiskFree v1.0
'
'                                                        (c)2005
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Option Explicit

        Const K = 1024

        Main

Sub Main

        Const DriveTypeRemovable = 1
        Const DriveTypeFixed        = 2
        Const DriveTypeNetwork        = 3
        Const DriveTypeCDROM        = 4
        Const DriveTypeRAMDisk        = 5
        Dim i, fso, Str, objDriveList

        Set fso = CreateObject("Scripting.FileSystemObject")
        Set objDriveList = fso.Drives

        For Each i in objDriveList
        If i.DriveType = DriveTypeFixed Then
                Str = Str & myDiskFreeCalc(i)
        End If
        Next

        MsgBox Str,,"DiskFree"

End Sub

Function myDiskFreeCalc(strDrivePath)

        Dim fso, objDrive, Str
        Dim TotalSizeBytes, TotalSizeGB
        Dim DiskUsedBytes, DiskUsedGB
        Dim DiskFreeBytes, DiskFreeGB
        Dim DiskFreePercentage

        Set fso = CreateObject("Scripting.FileSystemObject")
        Set objDrive = fso.GetDrive(fso.GetDriveName(strDrivePath))

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        TotalSizeBytes = FormatNumber(objDrive.TotalSize, 0)
        TotalSizeGB = FormatNumber(TotalSizeBytes / (K * K * K), 2)

        DiskFreeBytes = FormatNumber(objDrive.FreeSpace, 0)
        DiskFreeGB = FormatNumber(DiskFreeBytes / (K * K * K), 2)

        DiskUsedBytes = FormatNumber( TotalSizeBytes - DiskFreeBytes, 0)
        DiskUsedGB = FormatNumber((TotalSizeBytes - DiskFreeBytes) / (K * K * K), 2)

        DiskFreePercentage = FormatNumber( (DiskFreeBytes / TotalSizeBytes) * 100, 2)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Str = "[" & UCase(strDrivePath) & "] " & DiskFreePercentage & "% free" _
                & vbCrLf

        Str = Str & "TotalSize: " & TotalSizeGB & " GB" & vbCrLf
        Str = Str & "Disk Used: " & DiskUsedGB & " GB" & vbCrLf
        Str = Str & "Disk Free: " & DiskFreeGB & " GB" & vbCrLf & vbCrLf

        myDiskFreeCalc = Str

End Function