Retrieve the Free Space on a Mac OS Volume
· Jun 30, 08:08 AMOn the REALbasic mailing list, there is some interest in retrieving the amount of free space available on a Mac OS volume. It turns out that this information can be easily retrieved using a File Manager function.
Function FreeSpace(extends theVolume as FolderItem) As UInt64
#if targetMacOS
soft declare function FSGetVolumeInfo Lib "Carbon.framework" (volume as Int16, volumeIndex as Integer, actualVolume as Ptr, whichInfo as UInt32, info as Ptr, volumeName as Ptr, rootDirectory as Ptr) as Int16
const sizeOfFSVolumeInfo = 126
dim theInfo as new MemoryBlock(sizeOfFSVolumeInfo)
const kFSVolInfoSizes = &h0040
dim OSErr as Int16 = FSGetVolumeInfo(theVolume.MacVRefNum, 0, nil, kFSVolInfoSizes, theInfo, nil, nil)
if OSErr <> 0 then
break
return 0
end if
return theInfo.UInt64Value(48)
#endif
End Function
I’ve also added the method to macoslib .
The Apple documentation for FSGetVolumeInfo notes that changes to the free space value may not be immediately available. If you do not see what you expect, you should read the documentation for FSGetVolumeInfo.
Comment
Commenting is closed for this article.
Compiler warnings can't warn against stupidity When Does a Window Have an Attached Sheet?
Charles, Just a reminer, this has been a part of the Carbon Library Declares forever.
— Jordan · Jul 1, 12:57 AM · #
I have a fairly recent version of that project, and I couldn’t find it.
— charles · Jul 1, 09:43 AM · #