Is there a way to get the size on disk of a file like in the properties window:
I have tried:
(inside a batch file)
echo %~z1
,
for %i in (TestFile.txt) do echo %~zi
,
dir
But they only return the size of the file(s).
Is there any way to get the "size on disk" like the one seen in the properties window?
Interesting question. I'm not aware of the size on disk value being a property of any scriptable object. You could calculate it by getting filesize modulo bytes-per-cluster, subtracting that modulo from the file size, then adding the cluster size. (Edit: or use Aacini's more efficient calculation, which I'm still trying to understand.)
Many websites claim that
fsutil fsinfo ntfsinfo DRIVE:
is the best way to obtain the bytes per cluster. It seems that this method is fraught with peril, with different labels depending on locale and different number of lines for different versions of Windows. Additionally, as Marged says,fsutil
requires elevation. This WMI method seems to work more universally, and without requiring admin rights.