me consiguió este trabajo utilizando el código Publicado por @rekle como punto de partida El truco es usar NSDirectoryEnumerator, que lo hará de forma recursiva. Aquí está la función que escribí en caso de que alguien lo necesite.
- (NSArray *)recursivePathsForResourcesOfType:(NSString *)type inDirectory:(NSString *)directoryPath{
NSMutableArray *filePaths = [[NSMutableArray alloc] init];
// Enumerators are recursive
NSDirectoryEnumerator *enumerator = [[[NSFileManager defaultManager] enumeratorAtPath:directoryPath] retain];
NSString *filePath;
while ((filePath = [enumerator nextObject]) != nil){
// If we have the right type of file, add it to the list
// Make sure to prepend the directory path
if([[filePath pathExtension] isEqualToString:type]){
[filePaths addObject:[directoryPath stringByAppendingPathComponent:filePath]];
}
}
[enumerator release];
return [filePaths autorelease];
}
Swift, utilizando NSURL
func recursivePathsForResources(type type: String) -> [NSURL] {
// Enumerators are 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
}
Su título dice para obtener todos los caminos de recursos, pero el cuerpo dice que sólo recibe txt así que sí un poco las dos caras. : -/Vine aquí buscando una forma de obtener todos los archivos. – Jonny
Debería poder hacer lo mismo con NSDirectoryEnumerator a continuación, simplemente elimine el condicional que verifica el tipo de archivo. – smokingoyster