Results 1 to 3 of 3

Thread: Available Drive Space / Used Space

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Available Drive Space / Used Space

    Rick,

    Thanks for you help in the past with the code below, it has worked great for me. Is it possible to do something similar to also determine the amount of used space in a particular folder on the drive?

    "\\networkdrive\thisproject"

    PS. I removed the "Replace" statements from your code to make it functional for my network.

    Code:
    Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
                    Alias "GetDiskFreeSpaceExA" _
                   (ByVal lpDirectoryName As String, _
                    lpFreeBytesAvailableToCaller As Currency, _
                    lpTotalNumberOfBytes As Currency, _
                    lpTotalNumberOfFreeBytes As Currency _
                   ) As Long
    
    Function TotalBytes(ByVal DriveLetter As String) As Currency
      Dim BytesAvailableToCaller As Currency, FreeBytes As Currency
      GetDiskFreeSpaceEx DriveLetter, BytesAvailableToCaller, TotalBytes, FreeBytes
    End Function
    
    Function FreeBytes(ByVal DriveLetter As String) As Currency
      Dim BytesAvailableToCaller As Currency, TotalBytes As Currency
      GetDiskFreeSpaceEx DriveLetter, BytesAvailableToCaller, TotalBytes, FreeBytes
    End Function

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by JimHol View Post
    Thanks for you help in the past with the code below, it has worked great for me. Is it possible to do something similar to also determine the amount of used space in a particular folder on the drive?

    \\networkdrive\thisproject
    I do not have access to a network, so I cannot test this code out, but I think it should work with that type of folder reference (you will have to try it out and let me know)...
    Code:
    Function FolderSize(FolderPath As String) As Variant
      Dim FS As Object, Folder As Object
      Set FS = CreateObject("Scripting.FileSystemObject")
      Set Folder = FS.GetFolder(FolderPath & IIf(Right(FolderPath, 1) = "\", "", "\"))
      FolderSize = Folder.Size
    End Function

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Thanks Rick,

    I am sure this code will work as well as the other code. I will give it a try first thing tomorrow.

    Thanks again,
    Jim

Similar Threads

  1. Intersection of Overlapping Ranges:Space Operator
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  2. Replies: 1
    Last Post: 02-14-2013, 12:09 PM
  3. Saving Embedded Picture From Excel Workbook Sheet To Folder Hard Drive
    By littleiitin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 10-31-2011, 02:31 PM
  4. Replies: 0
    Last Post: 09-06-2011, 01:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •