如何查询“磁盘大小”文件信息? [英] How do I query "Size on disk" file information?

查看:81
本文介绍了如何查询“磁盘大小”文件信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为任何给定文件重现 Windows资源管理器->属性对话框->常规属性页中显示的行为。具体来说,我想重现磁盘大小字段的确切值。

I want to reproduce behaviour exhibited in the Windows Explorer -> Properties dialog -> General property page for any given file. Specifically I want to reproduce the exact value of the "Size on disk" field.

推荐答案

正如其他人所说,您需要使用 GetFileInformationByHandleEx ,但是您似乎需要使用 FILE_STANDARD_INFO FILE_ID_BOTH_DIR_INFO 。所需的信息在每个的 AllocationSize 成员中返回,但是第二个用于目录句柄,以列出其中的文件而不是目录本身(注意:不是递归的,只是顶层)。为了简化操作, FILE_STANDARD_INFO 具有 Directory 布尔值,因此如果不确定,请首先调用它。根据 FILE_ID_BOTH_DIR_INFO 的文档,

As others have said, you need to use GetFileInformationByHandleEx, but it looks like you need to use FILE_STANDARD_INFO or FILE_ID_BOTH_DIR_INFO. The information you want is returned in the AllocationSize member of each, but the second is for directory handles, to list files within instead of the directory itself (note: not recursive, just top-level). To make it easier, FILE_STANDARD_INFO has a Directory boolean, so call it first if you're not sure. According to the documentation for FILE_ID_BOTH_DIR_INFO,


AllocationSize
包含指定多少的值为文件分配了空间,以字节为单位。此值通常是基础物理设备的扇区或群集大小的倍数。

AllocationSize Contains the value that specifies how much space is allocated for the file, in bytes. This value is usually a multiple of the sector or cluster size of the underlying physical device.

这似乎为您提供了 Size

This seems to give you the Size on Disk information.

我还没有找到 FILE_ID_BOTH_DIR_INFO 结构的Delphi转换。困难似乎是最后一个成员, WCHAR FileName [1] ,它描述为:

I haven't found a Delphi translation of the FILE_ID_BOTH_DIR_INFO structure. The difficulty would seem to be the final member, WCHAR FileName[1], which is described as:


FileName [1]

包含文件名字符串的第一个字符。在内存中紧随其后的是字符串的其余部分。

FileName[1]
Contains the first character of the file name string. This is followed in memory by the remainder of the string.

我不确定在Delphi中如何处理。

I'm not sure how this would be handled in Delphi.

这篇关于如何查询“磁盘大小”文件信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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