I want to reproduce behaviour exhibited in the Windows Explorer -> Properties dialog -> General property page for any given file. Specifically I want to reproduce the exact value of the "Size on disk" field.
As others have said, you need to use GetFileInformationByHandleEx
, but it looks like you need to use FILE_STANDARD_INFO
or FILE_ID_BOTH_DIR_INFO
. The information you want is returned in the AllocationSize
member of each, but the second is for directory handles, to list files within instead of the directory itself (note: not recursive, just top-level). To make it easier, FILE_STANDARD_INFO
has a Directory
boolean, so call it first if you're not sure. According to the documentation for FILE_ID_BOTH_DIR_INFO
,
AllocationSize Contains the value that specifies how much space is allocated for the file, in bytes. This value is usually a multiple of the sector or cluster size of the underlying physical device.
This seems to give you the Size on Disk
information.
I haven't found a Delphi translation of the FILE_ID_BOTH_DIR_INFO
structure. The difficulty would seem to be the final member, WCHAR FileName[1]
, which is described as:
FileName[1]
Contains the first character of the file name string. This is followed in memory by the remainder of the string.
I'm not sure how this would be handled in Delphi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With