获取文件在iPhone的文档目录中的文件夹内 [英] Get Files Inside a folder in Document directory in iPhone

查看:99
本文介绍了获取文件在iPhone的文档目录中的文件夹内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone的新手,

I am new to iPhone,

我制作了一个应用程序,我正在下载一本书并将其存储在名为 book1Folder的文件夹中位于文档目录中。

I made an app in which, i am downloading a book and storing it in a folder called book1Folder which is inside Document directory.

现在我想要我的数组中所有书籍的名称,在 book1Folder 中有2本书,但是当我写的时候这段代码显示我的数组是3。

now i wants name of all books in my array, there are 2 books inside a book1Folder but when i write this code it shows me array count is 3.

这是我的代码片段,

-(void)viewWillAppear:(BOOL)animated{
    NSString *files;
    NSString *Dir=[self applicationDocumentsDirectory];
    Dir=[Dir stringByAppendingPathComponent:@"book1Folder"];

    NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:Dir];

    Downloadedepubs = [[NSMutableArray alloc]init];
    while(files = [direnum nextObject])
    {
        if([[files pathExtension] isEqualToString:@"epub"])
            NSLog(@"files=%@",files);
            [Downloadedepubs addObject:files];
    }
}

我的日志只显示2本书的名称,但是当我遍历数组它包含3个对象。

My log shows only name of 2 book, but when i loop through array it contains 3 objects.

[Downloadedepubs ObjectAtIndex:0]=.DS_Store;
[Downloadedepubs ObjectAtIndex:1]=abcd;
[Downloadedepubs ObjectAtIndex:2]=pqrs;

这是什么 .DS_Store 为什么会这样?

我们将不胜感激任何帮助。

推荐答案

在大括号中获取if块。它只影响if之后的第一行。

Get your if block in curly brackets. It affects only first line after if.

如下所示;

if([[files pathExtension] isEqualToString:@"epub"]) {
            NSLog(@"files=%@",files);
            [Downloadedepubs addObject:files];
}

这篇关于获取文件在iPhone的文档目录中的文件夹内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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