Get files inside a folder in the Document folder on iPhone

I'm new to the iPhone,

I created an application in which I download a book and save it in a folder called book1Folder , which is located inside the Document directory .

now I want the name of all the books in my array, there are 2 books inside book1Folder , but when I write this code, it shows me that the number of arrays is 3.

Here is my code snippet,

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

Only the name of 2 books is displayed in my journal, but when I loop through array contains 3 objects.

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

What is this .DS_Store , why is it coming?

Any help would be appreciated.

+1
source share
3 answers

Get your if block in braces. This only affects the first line after if.

As below;

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

.DS_Store is a hiden file on Mac for storing your file in the Folder.you folder you can delete it

0
source

Try the following:

  NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath:yourPathhere]; // Ignore any files except XYZ.epub for (NSString* file in e) { if (NSOrderedSame == [[file pathExtension] caseInsensitiveCompare:@"epub"]) { // Do something with file.epub [Downloadedepubs addObject:files]; } else if ([[[e fileAttributes] fileType] isEqualToString:NSFileTypeDirectory]) { // Ignore any subdirectories [e skipDescendents]; } } 
0
source

All Articles