zoukankan      html  css  js  c++  java
  • iphone获取当前磁盘信息

    获取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;

  • 相关阅读:
    JavaScript周报#185
    让你跟上nodejs的资源
    微信服务号开发笔记
    Algs4-2.1.15昂贵的交换
    Algs4-2.1.14出列排序
    Algs4-2.1.13纸牌排序-按花色排序
    Algs4-2.1.12令希尔排序打印出递增序列的每个元素所带来的比较次数和数组大小的比值
    Algs4-2.1.10在希尔排序中为什么实现h有序时不使用选择排序?
    Algs4-2.1.11希尔排序序列改为存数组
    Algs4-2.1.9给出希尔排序的轨迹
  • 原文地址:https://www.cnblogs.com/xkzy/p/3810826.html
Copyright © 2011-2022 走看看