W3cubDocs

/Nushell

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:

input output
list<string> table
string record

Examples

Parse a path

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

Replace a complex extension

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

Ignore the extension

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

Parse all paths in a list

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

Notes

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

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/path_parse.html