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

    获取iphone磁盘总大小、已使用空间、空闲空间 
    [代码]悦德财富:https://www.yuedecaifu.com
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    -(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;
             
            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
            NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]); 
        
        return totalFreeSpace;
    }
  • 相关阅读:
    如何得到需要下载文件的链接(路径)?
    Python之内存泄漏和内存溢出
    IO多路复用
    python-socket和进程线程协程(代码展示)
    Xshell(远程)连接不上linux服务器(防火墙介绍)
    Shell--变量
    Python读写配置文件模块--Configobj
    python文件处理之fileinput
    python之commands和subprocess入门介绍(可执行shell命令的模块)
    linux下 > /dev/null 2 > &1 的意思和如何在后台启动进程
  • 原文地址:https://www.cnblogs.com/oceansea/p/5949366.html
Copyright © 2011-2022 走看看