Saturday, August 11, 2012

GET FREE DISK SPACE **********

//*****************************************
-(float)GetFreeDiskSpaceInBytes
{
    float totalSpace = 0.0f;
    NSError *error = nil;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  

    if (dictionary)
        {
        NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];              //Or NSFileSystemSize for total size
        totalSpace = [fileSystemSizeInBytes floatValue];
    }
        else
        {
        NSLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);
    }  

    return totalSpace;
}

No comments:

Post a Comment