错误的文件系统信息

时间:2012-12-16 18:37:05

标签: objective-c macos cocoa

  

可能重复:
  Why does the value from NSFileSystemFreeSize differ from the free size reported in the iOS Settings?

我有这段代码:

NSError *error = nil;
NSString *outputDirectory = @"/Users/myuser/Desktop"

NSDictionary *fileSystemAttributes =
 [fileManager attributesOfFileSystemForPath:outputDirectory error:&error];

if (!error) {

    uint64_t freeSpace = (uint64_t)[fileSystemAttributes objectForKey:NSFileSystemFreeSize];

    NSLog(@"Free space in bytes: %lld.",freeSpace);
}

当我执行代码时,它给了我大约45 TB的可用空间,这是完全错误的!

我试过

outputDirectory = @"/";

但它也失败了。

我错过了什么吗? 谢谢你的时间。

1 个答案:

答案 0 :(得分:3)

来自文档:

  

NSFileSystemFreeSize文件系统属性字典中的键   其值表示文件系统上的可用空间量。该   对应的值是NSNumber对象

您应该将从objectForKey:获得的对象分配给NSNumber变量,然后从中提取您要使用的任何原始值(freeSpace)。