如何获取可可的目录大小和可用空间? [英] How to get Size and free space of a directory in cocoa?
问题描述
我想要存取目录的实际大小,以及目录中的可用空间。
我已经使用[NSFileManager defaultManager] attributesOfItemAtPath:path error:& error]方法。
此方法适用于文件,但对于目录,它不提供实际值。请帮助解决这个问题。
提前感谢。
I want to access the actual size of a directory, and also free space available in a directory. I already used [NSFileManager defaultManager]attributesOfItemAtPath:path error:&error] method. This method works fine for files but for directory, it does not provide actual value. Please help to solve this problem. Thanks in advance.
推荐答案
您可以使用此特定方法计算目录的大小,速度最快,使用Carbon,而不是NSEnumerator:
这里 a>
You can calculate the size of a directory using this particular method, the fastest, using Carbon, instead of NSEnumerator : here
要计算可用空间,可以使用该方法。确保您输入卷的完整路径:
To calculate free space, you could use that method. Make sure you enter the full path of the volume :
NSDictionary * fileAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:folder];
unsigned long long size = [[fileAttributes objectForKey:NSFileSystemFreeSize] longLongValue];
其中size是您要查找的内容。
Where size is what you're looking for.
这篇关于如何获取可可的目录大小和可用空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!