Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a working example of something like what you describe:</p> <pre><code>NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:@"/Users/bdesham/Sites"]; NSMutableArray *htmlFiles = [NSMutableArray new]; NSURL *path; while (path = [enumerator nextObject]) { if ([[path lastPathComponent] isEqualToString:@"index.html"]) { [htmlFiles addObject:@{ @"level" : [NSNumber numberWithInteger:[enumerator level]], @"path" : path }]; } } [htmlFiles sortUsingComparator:^NSComparisonResult(id obj1, id obj2) { return [obj1[@"level"] integerValue] &gt; [obj2[@"level"] integerValue]; }]; NSMutableArray *paths = [NSMutableArray arrayWithCapacity:[htmlFiles count]]; [htmlFiles enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [paths addObject:obj[@"path"]]; }]; </code></pre> <p>The idea here is as follows:</p> <ol> <li>Enumerate all of the files within the folder of interest.</li> <li>For each file that has the filename you want, add it to the <code>htmlFiles</code> array. The file is added as a dictionary so that we can store the depth (the result of calling <code>-[NSDirectoryEnumerator level]</code>) along with each filename.</li> <li>We now have an array containing all of the files in which we might be interested.</li> <li>Sort the array according to the files’ depths (the <code>@"level"</code> key in the dictionary).</li> <li>We don’t need the pathnames in dictionaries anymore, so create a new array containing just the pathnames (but in the same sorted order as before).</li> </ol> <p>At the end of this piece of code, the <code>paths</code> array contains the <code>NSURL</code>s of all files named “index.html”, with the files closest to the root first and those furthest from the root last. (Note that the ordering within the array of two files at the same directory level is undefined.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload