Question: Given an following files in the Documents directory --

```
Animals/Birds/file1.xyz
Animals/Birds/file2.xyz
Animals/Cats/file1.xyz
Cars/Ford/file1.xyz
Photos/MyAlbums/file1.xyz

```

And given that we have an `NSArray` of `NSURLs` to these files, is it possible to use an `NSPredicate` to filter the array by path or path/subpath? For example 

* Unique names of everything in the first level of the hierarchy (Animals, Cars, Photos)
* Unique names of everything in the second level (Birds, Cats)
* Files in the Animals directory -- (/Animals)
* Files in the Cats directory -- (/Animals/Cats)

Answer: 
Since these are actual file URLs in the actual Documents directory, why not use NSFileManager `contentsOfDirectoryAtURL:`? It directly answers the question you are asking ("files in the Cats directory").

Or, for more power, cycle through the files with an NSDirectoryEnumerator.
If you really wanted to filter an array of NSURLs you could do something like this:

```
- (NSArray *)filteredArray:(NSArray *)originalArray withSubpath:(NSString *)subpath {
    NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
        NSURL *url = (NSURL *)evaluatedObject;
        NSRange range = [[url path] rangeOfString:subpath];
        return (range.location == 0);
    }];
    return [originalArray filteredArrayUsingPredicate:predicate];
}

```

Here's how I tested it:

```
NSArray *urls = @[[NSURL URLWithString:@"Animals/Birds/file1.xyz"],
                  [NSURL URLWithString:@"Animals/Birds/file2.xyz"],
                  [NSURL URLWithString:@"Animals/Cats/file1.xyz"],
                  [NSURL URLWithString:@"Cars/Ford/file1.xyz"]];

NSLog(@"Before: %@", urls);
urls = [self filteredArray:urls withSubpath:@"Animals/Birds"];
NSLog(@"After: %@", urls);

```

The output log was:

```
Before: (
    "Animals/Birds/file1.xyz",
    "Animals/Birds/file2.xyz",
    "Animals/Cats/file1.xyz",
    "Cars/Ford/file1.xyz"
)
After: (
    "Animals/Birds/file1.xyz",
    "Animals/Birds/file2.xyz"
)

```

**Note**: It matches substrings, so it wouldn't match "/Animals" in this case because of the leading slash (unless both the array and the substring included the '/').