1.计算单个文件大小
+ (long long)fileSizeAtPath:(NSString*)filepath { NSFileManager* manager = [NSFileManager defaultManager]; if ([manager fileExistsAtPath:filepath]){ return [[manager attributesOfItemAtPath:filepath error:nil] fileSize]; } return 0; }
2.计算系统空间大小
/* *FOUNDATION_EXPORT NSString * const NSFileSystemSize;//系统总空间大小 *FOUNDATION_EXPORT NSString * const NSFileSystemFreeSize;//系统可使用空间大小 */ + (CGFloat)getStorage { NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; NSNumber *num = [fattributes objectForKey:NSFileSystemFreeSize]; return [num longLongValue]/1024.0/1024.0/1024.0; }
时间: 2024-11-09 00:42:26