VBA, MS Access MS Access в примерах

FSO - Размер папки в MB или GB

Public Function GetFolderSize(sFolderPath$) As Currency
'es - 21.06.2020 - Возвращает Размер папки в MB или GB
'----------------------------------------------------------------
'?GetFolderSize("d:\Temp")
'----------------------------------------------------------------
Dim FSO As Object, FSOFolder As Object
Dim cSize As Currency
Dim dSize As Double

On Error GoTo GetFolderSize_Err
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set FSOFolder = FSO.GetFolder(sFolderPath)
    dSize = CDbl(FSOFolder.Size)
    'cSize = dSize / 1024 ^ 2 ' в MB
    cSize = dSize / 1024 ^ 3 ' в GB
    GetFolderSize = cSize

GetFolderSize_End:
    On Error Resume Next
    Set FSOFolder = Nothing
    Set FSO = Nothing
    Err.Clear
    Exit Function

GetFolderSize_Err:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Function GetFolderSize.", _
        vbCritical, "Произошла ошибка!"
    Debug.Print "GetFolderSizeMB_Line: " & Erl & "."
    Err.Clear
    Resume GetFolderSize_End
End Function
Назад ToTop
L.E. 04.02.2024
Рейтинг@Mail.ru