User Tools

Site Tools


finding_20the_20free_20space_20on_20a_20disk

Finding the free space on a disk

by Richard Russell, October 2006

If you need to find out the amount of free space on a disk drive you can do that quite easily:

        drive$ = "C:\"
        SYS "GetDiskFreeSpace", drive$, ^SpC%, ^BpS%, ^Free%, ^Total%
        gbytes_total = SpC% * BpS% * Total% / 2^30
        gbytes_free  = SpC% * BpS% * Free% / 2^30

This code fragment sets gbytes_total to the total capacity of the drive and gbytes_free to the free (unused) space on the drive, both in Gigabytes.

If you only want to know the free space as a percentage of the total you don't need to calculate the values in Gbytes but simply use the Free% and Total% values:

        PRINT "The disk has ";INT(100*Free%/Total%+0.5);"% free space"
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
finding_20the_20free_20space_20on_20a_20disk.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1