Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 25th, 2006, 01:17 PM
Authorized User
 
Join Date: Jul 2004
Location: clapton-in-gordano, n.somerset, United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default Free space on disc

Due to some strange managerial decisions, I run a process on a 200Gb USB drive. However, the process eats a lot of space as it is used to unzip some huge text files before processing the files into Access. Is there a way that I can interrogate the drive (or any other drive, for that matter) from the process' main form to discover how much free space exists on it before I start the process, rather than the system stopping when the disc is full?

Thanks


Reply With Quote
  #2 (permalink)  
Old February 25th, 2006, 07:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hello,

The GetDiskFreeSpaceEx Win32 API call should get it for you. Just change the letter of your disk drive in the Test routine (my external HD is drive E:). I'm not sure what the difference is between the Free and Availble values reported. They are identical on my system.

Code:
Option Compare Database
Option Explicit

Private Type LARGE_INTEGER
    lowpart As Long
    highpart As Long
End Type

Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias _
    "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, _
    lpFreeBytesAvailableToCaller As LARGE_INTEGER, lpTotalNumberOfBytes _
    As LARGE_INTEGER, lpTotalNumberOfFreeBytes As LARGE_INTEGER) As Long

Sub Test()
    Dim lResult As Long
    Dim liAvailable As LARGE_INTEGER
    Dim liTotal As LARGE_INTEGER
    Dim liFree As LARGE_INTEGER
    Dim dblAvailable As Double
    Dim dblTotal As Double
    Dim dblFree As Double

    'Determine the Available Space, Total Size and Free Space of a drive
    lResult = GetDiskFreeSpaceEx("E:\", liAvailable, liTotal, liFree)

    'Convert the return values from LARGE_INTEGER to doubles
    dblAvailable = CLargeInt(liAvailable.lowpart, liAvailable.highpart)
    dblTotal = CLargeInt(liTotal.lowpart, liTotal.highpart)
    dblFree = CLargeInt(liFree.lowpart, liFree.highpart)

    'Display the results
    Debug.Print "Available Space:  " & dblAvailable & " bytes (" & _
                Format(dblAvailable / 1024 ^ 3, "0.00") & " G) " & vbCr & _
                "Total Space:      " & dblTotal & " bytes (" & _
                Format(dblTotal / 1024 ^ 3, "0.00") & " G) " & vbCr & _
                "Free Space:       " & dblFree & " bytes (" & _
                Format(dblFree / 1024 ^ 3, "0.00") & " G) "

End Sub

Private Function CLargeInt(Lo As Long, Hi As Long) As Double

    'This function converts the LARGE_INTEGER data type to a double

    Dim dblLo As Double, dblHi As Double

    If Lo < 0 Then
        dblLo = 2 ^ 32 + Lo
    Else
        dblLo = Lo
    End If

    If Hi < 0 Then
        dblHi = 2 ^ 32 + Hi
    Else
        dblHi = Hi
    End If

    CLargeInt = dblLo + dblHi * 2 ^ 32

End Function
HTH,

Bob

Reply With Quote
  #3 (permalink)  
Old February 25th, 2006, 09:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

MSDN says:

lpTotalNumberOfFreeBytes:

A pointer to a variable that receives the total number of free bytes on a disk.

lpFreeBytesAvailable

A pointer to a variable that receives the total number of free bytes on a disk that are available to the user who is associated with the calling thread.

Bob



Reply With Quote
  #4 (permalink)  
Old February 26th, 2006, 08:17 AM
Authorized User
 
Join Date: Jul 2004
Location: clapton-in-gordano, n.somerset, United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Many thanks Bob, you've saved my phone ringing at 2 a.m. with an irate user telling me "your programme's fallen over". Now they will know they have to perform houskeeping before they run.

Cheers!


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Web Site Space Asp_Developer ASP.NET 2.0 Basics 4 September 10th, 2012 03:03 AM
finding nth free space sumanth BOOK: Beginning Regular Expressions 0 August 23rd, 2007 05:41 AM
How to get free disk space in win32 liesberg C++ Programming 2 July 13th, 2007 03:17 PM
Wiping Free Space Michael109 Intro Programming 3 June 20th, 2007 02:10 AM
how to check the size of free space available to_joshi Linux 2 August 12th, 2004 04:22 PM



All times are GMT -4. The time now is 06:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.