Is there a way in VB6 where I could get the file's "Size on disk" (not the size).
I cannot achieve this by using the FileSystemObject's size property which only returns the file's size.

If this cannot be done, maybe a help on how to achieve these other options will do:
1. A way to capture what is displayed in the properties dialog box (right click a file then properties)
2. A command in the command prompt which can somehow retrieve "Size on disk"?

[Please refer to the attached file if you can't understand what I mean]


Any help will be very much appreciated. Thanks in advance.

Attachments sizeondisk.jpg 60.39 KB

The native GetAttr function will return some of the information you are looking for (read only, archive, hidden, and system) while the GetFileAttributes API will return a bit more information as will the GetFileAttributesEx API. Then there is the GetFileInformationByHandle API but for finding the size on disk, I cannot remember right off the top of my head.

Good Luck

Nice tip but it doesn't solve the problem. Thanks.

Anyone, please help...

Okay, I remember now. The size on disk is calculated by using the GetDiskFreeSpace API that returns bytes per sector as a sector is the smallest portion of addressable space on a disk. Meaning, if a disk has 4kb per sector and you save a 1kb file, it will take up an entire sector (4kb). On the other hand if you save a 5kb file, it will take up 2 sectors or 8kb...

Good Luck

From what I know, disks have different bytes per sector.
Could you give the function which can return the value of bytes per sector of a disk?
Or maybe the formula on how to achieve this.

I researched about the GetDiskFreeSpaceEx API from Microsoft.
[http://support.microsoft.com/kb/225144]

In the example given, three return values have been produced:
1. Available Space
2. Total Space
3. Free Space

Thanks.

Hello vb5prgrmr!

I have researched on the GetDiskFreeSpace API and yes it does answer my questions.
Actually, the one in MSDN is a help for Visual FoxPro and not for VB.
I'm not sure if I have installed MSDN correctly.

Anyways, this is how I solved it: (This is just the step-by-step procedure to solve the problem. The programmatic solution will be shown on my next post)
1. I need to figure out the ff. disk properties:
a. Bytes Per Cluster
b. Sectors Per Cluster
c. Bytes Per Sector

The GetDiskFreeSpace API can return "Sectors Per Cluster" and "Bytes Per Sector".

2. To get Bytes Per Cluster:
BytesPerCluster = SectorsPerCluster * BytesPerSector
ex. 8[SPC] * 512[BPS] = 4096[BPC]

3. By using the scrrun.dll, you can get the file size of the file to evaluate.
example.txt = 364 bytes

4. Divide the file size with Bytes Per Cluster.
FileSize = FileSize / BytesPerCluster
ex. 364 / 4096 = 0.0888671875

5. If filesize is in fraction (or has decimal), make it a whole no. then add 1 else retain the value.
ex. since(0.0888671875) make filesize = 1

6. Compute for size on disk
SizeOnDisk = fileSizeWholeNo * BytesPerCluster
ex. 1 * 4096 = 4096

Referring to my attached file, example.txt's property is:
size = 364 bytes
size on disk = 4096 bytes

I also tested this in Fat32 and the formula works.

Edited 6 Years Ago by cubekid: wrong content

This article has been dead for over six months. Start a new discussion instead.