path parse for path

Convert a path into structured data.

Signature

> path parse {flags}

Flags

  • --extension, -e {string}: Manually supply the extension (without the dot)

Input/output types:

inputoutput
list<string>table
stringrecord

Examples

Parse a path

> '/home/viking/spam.txt' | path parse
╭───────────┬──────────────╮
 parent /home/viking
 stem spam
 extension txt
╰───────────┴──────────────╯

Replace a complex extension

> '/home/viking/spam.tar.gz' | path parse --extension tar.gz | upsert extension { 'txt' }

Ignore the extension

> '/etc/conf.d' | path parse --extension ''
╭───────────┬────────╮
 parent /etc
 stem conf.d
 extension
╰───────────┴────────╯

Parse all paths in a list

> [ /home/viking.d /home/spam.txt ] | path parse
╭───┬────────┬────────┬───────────╮
 # │ parent │  stem  │ extension │
├───┼────────┼────────┼───────────┤
 0 /home viking d
 1 /home spam txt
╰───┴────────┴────────┴───────────╯

Notes

Each path is split into a table with 'parent', 'stem' and 'extension' fields. On Windows, an extra 'prefix' column is added.