iphone获取当前磁盘信息
2014-06-26 20:51
288 查看
获取iphone磁盘总大小、已使用空间、空闲空间
1. [代码][C/C++]代码
-(float)getFreeDiskspace {
float totalSpace;
float totalFreeSpace;
float totalUsedSpace;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes floatValue];
totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
totalUsedSpace = totalSpace - totalFreeSpace; http://www.huiyi8.com/css3/ float freePercent = totalFreeSpace/totalSpace;
float usedPercent = totalUsedSpace/totalSpace;
freePercentLabel.text = [[NSString stringWithFormat:@"%.2f",freePercent*100] stringByAppendingString:@"%"];
usedPercentLabel.text = [[NSString stringWithFormat:@"%.2f",usedPercent*100] stringByAppendingString:@"%"];
totalSpaceLabel.text = [[NSString stringWithFormat:@"%.2f",((totalSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
usedSpaceLabel.text = [[NSString stringWithFormat:@"%.2f",((totalUsedSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
freeSpaceLabel.text = [[NSString stringWithFormat:@"%.2f",((totalFreeSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
NSLog(@"Memory Capacity of %f GB with %f GB Free memory available.", ((totalSpace/1024.0f)/1024.0f/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f)/1024.0f);
} else { css3教程
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);
}
return totalFreeSpace;
}
1. [代码][C/C++]代码
-(float)getFreeDiskspace {
float totalSpace;
float totalFreeSpace;
float totalUsedSpace;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes floatValue];
totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
totalUsedSpace = totalSpace - totalFreeSpace; http://www.huiyi8.com/css3/ float freePercent = totalFreeSpace/totalSpace;
float usedPercent = totalUsedSpace/totalSpace;
freePercentLabel.text = [[NSString stringWithFormat:@"%.2f",freePercent*100] stringByAppendingString:@"%"];
usedPercentLabel.text = [[NSString stringWithFormat:@"%.2f",usedPercent*100] stringByAppendingString:@"%"];
totalSpaceLabel.text = [[NSString stringWithFormat:@"%.2f",((totalSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
usedSpaceLabel.text = [[NSString stringWithFormat:@"%.2f",((totalUsedSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
freeSpaceLabel.text = [[NSString stringWithFormat:@"%.2f",((totalFreeSpace/1024.0f)/1024.0f/1024.0f)] stringByAppendingString:@"GB"];
NSLog(@"Memory Capacity of %f GB with %f GB Free memory available.", ((totalSpace/1024.0f)/1024.0f/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f)/1024.0f);
} else { css3教程
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);
}
return totalFreeSpace;
}
相关文章推荐
- iphone获取当前流量信息
- iPhone获取当前位置信息
- 需求:获取iPhone当前Wi-Fi的SSID等网络信息
- iphone获取当前流量信息
- 个人封装的一个获取磁盘详细信息的类(如厂家,2级缓存等)
- VB中获取逻辑磁盘的信息
- 获取当前组策略配置的信息
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第六节 获取当前UDP连接情况
- 在vb中使用Iphlpapi.dll获取网络信息 第二章 第十一节 获取当前计算机的IP信息
- VB 获取所有逻辑磁盘信息 代码
- C#中获取逻辑磁盘、网卡MAC地址、CPUID等信息的代码
- UltraWebGrid获取鼠标点击的当前行的信息
- 获取当前调用函数的信息
- WinAPI: GetDiskFreeSpaceEx - 获取磁盘容量信息
- 获取磁盘空间信息(十四)
- 在Windows下通过JConfig获取磁盘剩余空间信息
- 获取本地磁盘信息(WMI)
- 获取当前区域下所有子区域信息的webpart
- 关于gridview获取当前行信息的这个古老的话题。
- HOW TO:获取当前Office应用程序的安装版本语言等信息