iphone - How do I get all resource paths in my bundle recursively in iOS? -


i have "unzipped" folder in application bundle. need resource paths files of type txt. i've been using this,

nsarray *filepaths = [nsbundle pathsforresourcesoftype:@"txt" indirectory:[[[nsbundle mainbundle] bundlepath] stringbyappendingstring:@"/unzipped"]]; 

but gets files in first directory. there recursive version of somewhere i'm missing?

i got working using code posted @rekle starting point. trick use nsdirectoryenumerator, recursively. here's function wrote in case needs it.

- (nsarray *)recursivepathsforresourcesoftype:(nsstring *)type indirectory:(nsstring *)directorypath{      nsmutablearray *filepaths = [[nsmutablearray alloc] init];      // enumerators recursive     nsdirectoryenumerator *enumerator = [[[nsfilemanager defaultmanager] enumeratoratpath:directorypath] retain];      nsstring *filepath;      while ((filepath = [enumerator nextobject]) != nil){          // if have right type of file, add list         // make sure prepend directory path         if([[filepath pathextension] isequaltostring:type]){             [filepaths addobject:[directorypath stringbyappendingpathcomponent:filepath]];         }     }      [enumerator release];      return [filepaths autorelease]; } 

swift, using nsurl

func recursivepathsforresources(type type: string) -> [nsurl] {      // enumerators recursive     let enumerator = nsfilemanager.defaultmanager().enumeratoratpath(bundlepath)     var filepaths = [nsurl]()      while let filepath = enumerator?.nextobject() as? string {          if nsurl(fileurlwithpath: filepath).pathextension == type {             filepaths.append(bundleurl.urlbyappendingpathcomponent(filepath))         }     }      return filepaths } 

Comments