﻿-(void)scanURLIgnoringExtras:(NSURL *)directoryToScan
{
    // Create a local file manager instance
    NSFileManager *localFileManager=[[NSFileManager alloc] init];

    // Enumerate the directory (specified elsewhere in your code)
    // Request the two properties the method uses, name and isDirectory
    // Ignore hidden files
    // The errorHandler: parameter is set to nil. Typically you'd want to present a panel
    NSDirectoryEnumerator *dirEnumerator = [localFileManager enumeratorAtURL:directoryToScan
                        includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey,
                                                    NSURLIsDirectoryKey,nil]
                        options:NSDirectoryEnumerationSkipsHiddenFiles
                        errorHandler:nil];

    // An array to store the all the enumerated file names in
    NSMutableArray *theArray=[NSMutableArray array];

    // Enumerate the dirEnumerator results, each value is stored in allURLs
    for (NSURL *theURL in dirEnumerator) {

        // Retrieve the file name. From NSURLNameKey, cached during the enumeration.
        NSString *fileName;
        [theURL getResourceValue:&fileName forKey:NSURLNameKey error:NULL];

        // Retrieve whether a directory. From NSURLIsDirectoryKey, also
        // cached during the enumeration.
        NSNumber *isDirectory;
        [theURL getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];

        // Ignore files under the _extras directory
        if (([fileName caseInsensitiveCompare:@"_extras"]==NSOrderedSame) &&
            ([isDirectory boolValue]==YES))
        {
            [dirEnumerator skipDescendants];
        }
        else
        {
            // Add full path for non directories
            if ([isDirectory boolValue]==NO)
                [theArray addObject:theURL];

        }
    }

    // Do something with the path URLs.
    NSLog(@"theArray - %@",theArray);

    // Release the localFileManager.
    [localFileManager release];

}