List Files in SubFolder (only in SubFolders )from a Folder
I need get list files in subFolder from a Folder main.
This is my code, but the value "filelist1" always show me empty array.
//
// ViewController.m
// MoveFiles
//
// Created by Jose Antonio Vazquez Mingorance on 10/10/15.
// Copyright (c) 2015 Jose Vazquez. All rights reserved.
//
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
// Solo los directorios
- (BOOL)onlyFolders:(int)i filelist:(NSArray *)filelist url:(NSURL *)url filemgr:(NSFileManager *)filemgr {
NSString *path = [[url path] stringByAppendingPathComponent:[filelist objectAtIndex: i]];
BOOL isDir = NO;
[filemgr fileExistsAtPath:path isDirectory:(&isDir)];
return isDir;
}
// Listado de archivos
// Abre panel de seleccion de carpeta
- (IBAction)AbreDirectorio:(id)sender {
NSOpenPanel *panel = [NSOpenPanelopenPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:YES]; // yes if more than one dir is allowed
NSInteger clicked = [panel runModal];
if (clicked == NSFileHandlingPanelOKButton) {
for (NSURL *url in [panel URLs]) {
NSFileManager *filemgr;
NSArray *filelist;
long count;
int i;
NSString *subDir;
NSArray *filelist1;
NSMutableString *urlSub = [[NSMutableStringalloc]init];
NSString *enlace = @"/";
NSString *subDir1;
// NSString *immutableString ;
long count1;
long j;
filemgr = [NSFileManager defaultManager];
filelist = [filemgr contentsOfDirectoryAtPath: [url path] error: nil];
count = [filelist count];
// Todos los archivos
for (i = 0; i < count; i++)
{
BOOL isDir;
isDir = [self onlyFolders:i filelist:filelist url:url filemgr:filemgr];
if (isDir){
// Subdirectorios
//NSLog(@"%@", url);
// NSLog (@"%@", [filelist objectAtIndex: i]);
NSString *temp1 = [url absoluteString];
NSString *temp2 = (NSString *)[filelist objectAtIndex: i] ;
subDir = [temp1 stringByAppendingString:temp2];
subDir1 = [subDir stringByAppendingString:enlace];
NSLog(@"%@", urlSub);
// filelist1 show always empy
filelist1 = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:subDir1 error:nil];
count1 = [filelist1 count];
for (j = 0; j < count; j++)
{
NSLog (@"%@", [filelist1 objectAtIndex: j]);
}
}
}
}
NSLog(@"Fin");
}
}
@end
iMac, OS X Yosemite (10.10.5), Is a general application