Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDirectoryEnumerator And Subfolders

I have an iPhone app that searches a folder, collates an an array of all the audio files, and lets them be played back. The problem is that if there is a subfolder within the folder I am searching, it will just skip over it/not go into its contents.

My code is as follows:

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory];

 NSString *pname;

 while (pname = [direnum nextObject])
{
      [musicArray addObject:[pname stringByDeletingPathExtension]];
}

What I want to do is continue to search its subfolders, how would I go about doing that?

like image 957
Matthew Roberts Avatar asked May 08 '10 13:05

Matthew Roberts


1 Answers

It does it automatically. From the documentation:

An enumeration is recursive, including the files of all subdirectories, and crosses device boundaries. An enumeration does not resolve symbolic links, or attempt to traverse symbolic links that point to directories.

like image 116
Dave DeLong Avatar answered Nov 15 '22 10:11

Dave DeLong