ios 工程的缓存大小

//获取缓存文件路径

-(NSString *)getCachesPath{

    // 获取Caches目录路径

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES);

    NSString *cachesDir = [paths objectAtIndex:0];

    

    NSString *filePath = [cachesDir stringByAppendingPathComponent:@"com.nickcheng.NCMusicEngine"];

    

    return filePath;

}

///计算缓存文件的大小的M

- (long long) fileSizeAtPath:(NSString*) filePath{

    NSFileManager* manager = [NSFileManager defaultManager];

    if ([manager fileExistsAtPath:filePath]){

        

//        //取得一个目录下得所有文件名

//        NSArray *files = [manager subpathsAtPath:filePath];

//        NSLog(@"files1111111%@ == %ld",files,files.count);

//        

//        // 从路径中获得完整的文件名(带后缀)

//        NSString *exe = [filePath lastPathComponent];

//        NSLog(@"exeexe ====%@",exe);

//        

//        // 获得文件名(不带后缀)

//        exe = [exe stringByDeletingPathExtension];

//        

//        // 获得文件名(不带后缀)

//        NSString *exestr = [[files objectAtIndex:1] stringByDeletingPathExtension];

//        NSLog(@"files2222222%@  ==== %@",[files objectAtIndex:1],exestr);

        

        

        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];

    }

    

    return 0;

}

- (float ) folderSizeAtPath:(NSString*) folderPath{

    NSFileManager* manager = [NSFileManager defaultManager];

    if (![manager fileExistsAtPath:folderPath]) return 0;

    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath]objectEnumerator];//从前向后枚举器//////

    NSString* fileName;

    long long folderSize = 0;

    while ((fileName = [childFilesEnumerator nextObject]) != nil){

        NSLog(@"fileName ==== %@",fileName);

        NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];

        NSLog(@"fileAbsolutePath ==== %@",fileAbsolutePath);

        folderSize += [self fileSizeAtPath:fileAbsolutePath];

    }

    NSLog(@"folderSize ==== %lld",folderSize);

    return folderSize/(1024.0*1024.0);

}

-(void)ss{

    // 获取Caches目录路径

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES);

    NSString *cachesDir = [paths objectAtIndex:0];

    

    NSLog(@"cachesDircachesDir == %@",cachesDir);

    //读取缓存里面的具体单个文件/或全部文件//

    NSString *filePath = [cachesDir stringByAppendingPathComponent:@"com.nickcheng.NCMusicEngine"];

    NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath];

    NSLog(@"filePathfilePath%@ ==array==== %@",filePath, array);

    

    

    NSFileManager* fm=[NSFileManager defaultManager];

    if([fm fileExistsAtPath:filePath]){

        //取得一个目录下得所有文件名

        NSArray *files = [fm subpathsAtPath:filePath];

        NSLog(@"files1111111%@ == %ld",files,files.count);

        

        // 获得文件名(不带后缀)

        NSString * exestr = [[files objectAtIndex:1] stringByDeletingPathExtension];

        NSLog(@"files2222222%@  ==== %@",[files objectAtIndex:1],exestr);

    }


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值