Seems like we need a substring check here too -- otherwise two directory paths of the same length would be confused for each other.  It'd also be good to add a comment saying the intent of this line, e.g. "is this directory the parent of this search result set's file"