Path Component Common Ancestor

Find a lexical component-level common ancestor of normalized absolute POSIX paths; character-prefix and filesystem ancestry are not inferred.

Description

Find a lexical component-level common ancestor of normalized absolute POSIX paths; character-prefix and filesystem ancestry are not inferred.

A common path ancestor depends on whole components rather than a textual character prefix.

When to use this tool

Find a lexical component-level common ancestor of normalized absolute POSIX paths; character-prefix and filesystem ancestry are not inferred.

  • Prepare the supplied left, right fields for this operation.
  • Compare the complete example with the representation used by your own input before carrying the result into another step.

How to use the tool and how it works

  1. Enter left, right. Use the exact text syntax, units and index conventions explained below.
  2. Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
  3. Read result.ancestor, result.sharedComponentCount. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Require absolute POSIX paths, collapse literal dot navigation and return slash plus their common leading component sequence, with sharedComponentCount.1

Input fieldMeaning and representationAccepted input
leftleft.Text; at most 8,192 UTF-16 code units, subject to the grammar above
rightright.Text; at most 8,192 UTF-16 code units, subject to the grammar above
Output fieldInterpretation
resultObject containing the named outputs below.
result.ancestorThe ancestor value under the stated formula or text convention.
result.sharedComponentCountThe shared component count value under the stated formula or text convention.
json
{
  "input": {
    "left": "/a/b",
    "right": "/a/c"
  },
  "output": {
    "result": {
      "ancestor": "/a",
      "sharedComponentCount": 1
    }
  }
}

Limitations and assumptions

  • The root is returned when no components match. This is lexical ancestry, without symlink resolution or file existence checks.
  • Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
  • String lists have at most 128 entries of at most 128 code units; matrices have at most 128 rows and columns. Larger numeric lists and parsed JSON have separate bounded budgets. Nonfinite results and excessively large serialized outputs are rejected.
  • Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.

Alternative or Complementary methods

Use a filesystem-aware implementation with appropriate platform semantics for actual file operations. Literal slash components, Unicode comparison and filename plans do not resolve symlinks or atomically reserve a destination.

References

  1. Tool behavior and example: Path Component Common Ancestor — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies