Sunday, April 21, 2013

NSFileManager NSFileSystemFreeSize example objc




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 that specifies the amount of free space on the file system in bytes. The value is determined by statfs(). (NSFileSystemFreeSize)
Available in OS X v10.0 and later.
Declared in NSFileManager.h.


Example of NSFileSystemFreeSize


NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/"
                                                                                   error:&error];
unsigned long long freeSpace = [[fileAttributes objectForKey:NSFileSystemFreeSize] longLongValue];
NSLog(@"free disk space: %dGB", (int)(freeSpace / 1073741824));