有没有一种方法来输出文件大小在批量盘? [英] Is there a way to output file size on disk in batch?

查看:256
本文介绍了有没有一种方法来输出文件大小在批量盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让一个文件的磁盘像在属性窗口大小:

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

我曾尝试:

(内一个批处理文件)

echo %~z1

for %i in (TestFile.txt) do echo %~zi

dir

但他们只返回文件(S)的大小。

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?

推荐答案

有趣的问题。我不知道在磁盘上的值是任何脚本化的对象的属性的大小。你可以通过获取文件大小模字节每簇,减去文件大小模,然后加入簇的大小计算。 (编辑:或使用Aacini更高效的计算,我还在努力理解)

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. ( 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%

许多网站声称, FSUTIL fsinfo列显ntfsinfo DRIVE:是获得每个群集的字节数的最佳途径。看来,这种方法是充满了危险,与根据对不同版本的Windows的行区域和不同数量不同的标签。此外,由于Marged说, FSUTIL 需要提升。此WMI方法似乎更普遍地工作,而不需要管理员权限。

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.

感谢JosefZ,Marged和Aacini您的所有输入!

这篇关于有没有一种方法来输出文件大小在批量盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆