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.)
@echo off
setlocal
for %%I in (Testfile.txt) do (
set "fs=%%~zI"
for /f %%J in (
'wmic volume where "driveletter='%%~dI'" get blocksize /value'
) do 2>nul set /a %%J
)
echo Size: %fs%
set /a ondisk = ((fs-1)/blocksize+1) * blocksize
echo Size on disk: %ondisk%
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.
Thanks JosefZ, Marged, and Aacini for all your input!
This is not intended to be an answer, just the values @rojo asked for:
NTFS-Volumeseriennummer 0xacf01e6ef01e3ed0
NTFS-Version : 3.1
LFS-Version : 2.0
Anzahl der Sektoren : 0x000000000ed737ff
Gesamtzahl Cluster : 0x0000000001dae6ff
Freie Cluster : 0x00000000008c8d41
Insgesamt reserviert : 0x0000000000000f70
Bytes pro Sektor : 512
Bytes pro physischem Sektor : 512
Bytes pro Cluster : 4096
Bytes pro Dateidatensatzsegment : 1024
Cluster pro Dateidatensatzsegment : 0
Gültige MFT-Datenlänge : 0x000000001c1c0000
MFT-Start-LCN : 0x00000000000c0000
MFT2-Start-LCN : 0x0000000000000002
MFT-Zonenstart : 0x00000000018a8ee0
MFT-Zonenende : 0x00000000018b12e0
Ressourcen-Manager-Bezeichner: A81246B1-33B0-11E4-A94B-AEB4ABF863CB
This is from a German Windows 8.1. I think if it is necessary to make the batch locale independent you can not take the grepping approach. Instead scripting the appropriate filesystem object by using scripting host will be one solution.
The WMIC
command has this result ...
SOMENAME,4096,C:\
... plus the advantage that I don't need to run this command with administrative rights.
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