Objective c 从选定文件夹中获取大小为>;100MB及其路径目标c

Objective c 从选定文件夹中获取大小为>;100MB及其路径目标c,objective-c,cocoa,size,nsfilemanager,Objective C,Cocoa,Size,Nsfilemanager,我想获取mac系统中所有文件及其路径和大小的列表 因此,我只想过滤那些文件大小超过100MB的文件 我使用下面的代码得到了系统的大小 NSError *error; NSFileManager *fileManager = [NSFileManager defaultManager]; NSDictionary *fileAttributes = [fileManager attributesOfFileSystemForPath:@"/" error:&error]; 现在,我想获

我想获取mac系统中所有文件及其路径和大小的列表

因此,我只想过滤那些文件大小超过100MB的文件

我使用下面的代码得到了系统的大小

NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [fileManager attributesOfFileSystemForPath:@"/" error:&error];
现在,我想获得文件列表及其路径和大小

我找了很多,但都不符合我的要求

请在这方面帮助我


提前感谢…

我得到了以下场景的解决方案

谢谢你给我这个主意

首先,我选择了一个文件夹的路径。然后,为了仅获取子文件夹,我使用了
NSDirectoryEnumerator
,然后使用代码查找文件的大小

得到文件大小后,我检查文件大小并将其添加到数组中

所以它成功了

NSString *Path = [NSString stringWithFormat:@"/Users/%@/",NSUserName()];

NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:Path];

NSString *file;
NSMutableArray *arrList = [[NSMutableArray alloc]init];

 while ((file = [de nextObject]))
 NSLog(@"file %@",file);

 Path = [NSString stringWithFormat:@"/Users/%@/",NSUserName()];

 Path = [Path stringByAppendingString:file];
 NSLog(@"path %@",Path);
NSError *attributesError = nil;

 NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:Path error:&attributesError];

 NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
 long long fileSize = [fileSizeNumber longLongValue];
 NSLog(@"%lld",fileSize);

 float sizeKB = ((float)fileSize / 1000);
 NSLog(@"%f",sizeKB);

 float sizeMB = ((float)fileSize / 1000000);
 NSLog(@"%f",sizeMB);

 if (sizeMB >= 100.0)
 {
     [arrList addObject:file];
     [test addObject:file.lastPathComponent];
 }

希望它对其他人也有帮助。

EnumeratorURL:includingPropertiesForKeys:options:errorHandler:
也许?@CRD:我如何实现它???在
EnumeratorURL:includingPropertiesForKeys:options:errorHandler:
的文档中,有一个示例代码,它遍历一棵树,收集所有路径,同时忽略某些路径文件夹。您可以以此为基础在树上行走并收集所有尺寸。如果你陷入困境,问另一个问题,并包括你的代码,有人可能会帮助你。