0

Possible Duplicate:
Why does the value from NSFileSystemFreeSize differ from the free size reported in the iOS Settings?

I have this code:

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);
}

When I execute the code, it gives me around 45 TB of free space, which is totally wrong!

I have tried with

outputDirectory = @"/";

but it also fails.

Am I missing something? Thank you for your time.

Community
  • 1
  • 1
Zi0P4tch0
  • 63
  • 1
  • 5

1 Answers1

3

From the documentation:

NSFileSystemFreeSize The key in a file system attribute dictionary whose value indicates the amount of free space on the file system. The corresponding value is an NSNumber object

You should assign the object you get from objectForKey: to a NSNumber variable and then extract whatever primitive value you want to use (freeSpace) from that.

Phillip Mills
  • 30,195
  • 4
  • 39
  • 55