Is there a way to print the size of a file on disk in batch mode?

Is there a way to get the size on the disk of a file, for example, in the properties window:

I tried:

(inside the 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 a way to get the "size on disk" like the one seen in the properties window?

+6
source share
2 answers

Interest Ask. I do not know what size on disk is a property of any script object. You can calculate it by receiving files modulo bytes per cluster, subtracting this modulo from the file size, and then adding the cluster size. ( Edit: or use a more efficient Aacini 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 get bytes per cluster. It seems that this method is fraught with danger, with different labels depending on the language and different number of lines for different versions of Windows. In addition, Marged says, fsutil requires a boost. This WMI method works more universally and does not require administrator rights.

Thanks to JosefZ, Marged and Aacini for all your data!

+5
source

This is not meant to be answered, just the @rojo values ​​requested:

 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 German Windows 8.1. I think that if you want independence from the party to be independent, you cannot use the grepping approach. Instead, the script for the corresponding file system object using the script node will be one of the solutions.

The WMIC team has this result ...

 SOMENAME,4096,C:\ 

... plus the advantage that I do not need to run this command with administrator privileges.

+2
source

Source: https://habr.com/ru/post/989282/


All Articles