从选定的文件夹中获取文件列表,文件夹大小> 100MB,路径目标为c [英] Get the list of files from selected folders having sizes >100MB with their paths objective c

查看:118
本文介绍了从选定的文件夹中获取文件列表,文件夹大小> 100MB,路径目标为c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得所有文件的列表及其路径&


$ b











$ b b

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

  NSError * error; 

NSFileManager * fileManager = [NSFileManager defaultManager];
NSDictionary * fileAttributes = [fileManager attributesOfFileSystemForPath:@/error:& error];

现在我想得到文件列表及其路径和大小。





我搜索了很多,但是那些不能满足我的要求。



请求帮助我。



提前感谢...

解决方案

我有以下情况的解决方案。



感谢 CRD 给我这个想法。



首先,我走了一个文件夹的路径。然后为了得到子文件夹,我使用 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:& attributeError];

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];
}

希望它也能帮助别人。


I want to get the list of all files with their paths & sizes for my mac system.

From that, I want to filter only those files which have file size above 100 MB.

I got the size of my system using the below code.

NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [fileManager attributesOfFileSystemForPath:@"/" error:&error];

Now I want to get the list of files with their paths and sizes.

I searched a lot but those couldn't meet to my requirements.

Pleas help me on this.

Thanks in advance...

解决方案

I got my solution with the following scenario.

Thanks CRD for giving me the idea.

First, I took a path of a folder. Then for getting subfolders only, I used NSDirectoryEnumerator and then I used the code to find the size of file.

Once I got the size of the file, then I checked the file size and added to my array.

So it worked.

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];
 }

Hope it helps someone else also.

这篇关于从选定的文件夹中获取文件列表,文件夹大小> 100MB,路径目标为c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆