path parse

For path.

Convert a path into structured data.

Command Type

built-in

Signature

> path parse {flags}

Flags

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

Input/output types:

input output
string record
list<string> table

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.

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.