文件大小在雪豹 [英] File size in Snow Leopard

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

问题描述

我想弄清楚如何根据文件或目录的大小分别将文件(或目录)的字节大小转换为千字节,兆字节,千兆字节等等,以便与Finder在面板中显示的内容相匹配当你点击获取信息。



字节大小,我完全匹配的字节大小报告在Finder,但我不知道如何获取文件



我知道在10.6中我们使用base 10,所以一个千字节是1000字节,不是1024,但将字节计数除以1000(或1000 ^ 2,1000 ^ 3等)与Finder报告的不匹配。



Finder:一个330字节的文本文件显示为一个4KB文件(所以我的初始猜想是将所有文件大小四舍五入到4KB数字),但389,022字节目录显示为418KB(方式多于舍入 - 高达4KB,所以我的猜测是错误的)。此外,一个1,315,291,136字节的文件显示为1.33GB。



那么任何人都可以这么美好吗?如何计算这些数字?



预先感谢您的帮助!



p PS自从我开始编程以来,我一直是100%的可可性,我从来没有使用过Carbon框架(我知道它非常强大,我只是不知道如何使用它)。我提到这只是为了防止任何人想给我一个碳解决方案,假设我知道如何使用它。 在HFS中,每个文件将占用4,096个字节的倍数( 块大小)。



如果您的目录包含一千个1字节文件,则该目录占用的总大小为

 (1000 * 4,096)= 4,096,000 = 4.1 MB,


b $ b

虽然目录使用的字节数仍然是

  1 * 1000 = 1,000字节。 


I'm trying to figure out how to convert a file's (or directory's) byte size into kilobytes, megabytes, gigabytes, etc... respectively according the file's or directory's size so that is matches what the Finder displays in the panel when you hit "Get Info".

The byte size I get perfectly matches the byte size as reported in Finder, but I can't figure out how to get the file's size (as displayed by the Finder in KB, MB, GB, etc) to match.

I know in 10.6 we use base 10, so a kilobyte is 1000 bytes and not 1024, but dividing the byte count by 1000 (or 1000^2, 1000^3, etc) doesn't match what the Finder reports.

For instance, in the Finder: a 330-byte text file is displayed as a 4KB file (so my initial guess would be to round-up all file sizes to 4KB figures), but 389,022-byte directory is displayed as a 418KB (way more than rounding-up to 4KB, so my guess is wrong). Also a 1,315,291,136-byte file is displayed as 1.33GB.

So can anyone please be so kind as to shed some light here? How are these figures calculated? I've looked all around and haven't been able to find an answer.

Thanks in advance for your help!

P.S. I've always been 100% Cocoa-oriented since I started programming and I've never used the Carbon framework before (I know it's very powerful, I just don't know how to use it). I mention this just in case anyone wants to give me a Carbon solution assuming I know how to use it. I don't.

解决方案

In HFS+ each file will occupy a multiple of 4,096 bytes (the "block size").

If your directory contains one thousand 1-byte files, the total size occupied by the directory would be

(1000 * 4,096) = 4,096,000 = 4.1 MB,

although the number of bytes used by the directory is still

1 * 1000 = 1,000 bytes.

这篇关于文件大小在雪豹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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