PHF Logo

PHF Consultancy


Development | Consultancy | Training

www Search this site
Powered by
Google
Home

Email

BookMark
Home Contact Us Products Services Technology How To... Partners Other Links

How to get the free disk space on C drive (Windows Only)

 

The following example show how to obtain the free space on a given drive. Using the function 'GetDiskFreeSpaceA' within the kernel32.dll

The code can be download from here.

.main getfreespace

.define DRIVELETTER    'c:\'

.align
record ivar
    kernel32    ,D_ADDR
    Sectors    ,i4
    bytes    ,i4
    freec    ,i4
    totalc    ,i4
    stat    ,i4
record var
    totalf    ,d18

record avar
    a1    ,a1

.proc
    open(1, o, 'tt:')

    ;open Windows DLL
    kernel32 = %dll_open('kernel32')

    clear sectors, bytes, freec, totalc
    ;call function to get free diskspace for given drive letter
    stat = %dll_call(kernel32,, 'GetDiskFreeSpaceA', DRIVELETTER, ^addr(sectors), ^addr(bytes), ^addr(freec), ^addr(totalc))
    if (stat)
        begin
        ;calculate total free bytes
        totalf = sectors * bytes * freec
        ;display total free bytes
        display(1, "Free Space(bytes): "+%string(totalf), 13, 10)
        ;display total free Kilo bytes
        display(1, "Free Space(KB): "+%string(totalf/1024), 13, 10)
        ;display total free Mega bytes
        display(1, "Free Space(MB): "+%string(totalf/1048576), 13, 10)
        end

    xcall dll_close(kernel32)

    reads(1,a1)
    close 1
    stop
.end

If you have any comments on this code. Please let me know.


Note: Synergy DBL Version 7 or higher required.

 

Valid HTML 4.01! Privacy Policy

Copyright © 1999-2007 PHF Consultancy
Banner images are trademarks of the companies represented