objective-c – 如何使用目标c获取ipad中目录中的所有文件

objective-c – 如何使用目标c获取ipad中目录中的所有文件,第1张

概述我需要获取目录中的所有文件,包括所有子目录和每个子目录中的所有文件.在目标C中,我尝试使用此方法 [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil] 但它只是给我一个目录filePath中的内容文件数组,我不能得到子目录中的所有文件,有人可以帮助我? 谢谢 - (void)scanPath:(N 我需要获取目录中的所有文件,包括所有子目录和每个子目录中的所有文件.在目标C中,我尝试使用此方法
[[NSfileManager defaultManager] contentsOfDirectoryAtPath:filePath error:nil]

但它只是给我一个目录filePath中的内容文件数组,我不能得到子目录中的所有文件,有人可以帮助我?

谢谢

解决方法
- (voID)scanPath:(Nsstring *) sPath {    BOol isDir;    [[NSfileManager defaultManager] fileExistsAtPath:sPath isDirectory:&isDir];    if(isDir)    {        NSArray *contentOfDirectory=[[NSfileManager defaultManager] contentsOfDirectoryAtPath:sPath error:NulL];        int contentcount = [contentOfDirectory count];        int i;        for(i=0;i<contentcount;i++)        {            Nsstring *filename = [contentOfDirectory objectAtIndex:i];            Nsstring *path = [sPath stringByAppendingFormat:@"%@%@",@"/",filename];            if([[NSfileManager defaultManager] isDeletablefileAtPath:path])            {                   NSLog(path);                [self scanPath:path];            }        }    }    else    {        Nsstring *msg=[Nsstring stringWithFormat:@"%@",sPath];        NSLog(msg);    }}

你可以调用这个函数来记录目录中的所有文件,希望这会有所帮助.

总结

以上是内存溢出为你收集整理的objective-c – 如何使用目标c获取ipad中目录中的所有文件全部内容,希望文章能够帮你解决objective-c – 如何使用目标c获取ipad中目录中的所有文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1082746.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存