github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/types/path.md (about) 1 # `path` 2 3 > Structured object for working with file and directory paths 4 5 ## Description 6 7 The `path` type Turns file and directory paths into structured objects. 8 9 The root directory (typically `/`) is counted as a directory. If a path is 10 relative rather than absolute then `/` will be excluded from outputted string. 11 12 ## Examples 13 14 **Return the first two elements in a path:** 15 16 ``` 17 » $PWD[..2] 18 /Users/ 19 ``` 20 21 **Check if path exists:** 22 23 ``` 24 » set path foobar="/dev/foobar" 25 » $foobar.2.Exists 26 ``` 27 28 **Example of `path` data structure:** 29 30 ``` 31 » set path foobar="/dev/foobar" 32 » $foobar -> format json 33 [ 34 { 35 "Exists": true, 36 "IsDir": true, 37 "IsRelative": false, 38 "Value": "/" 39 }, 40 { 41 "Exists": true, 42 "IsDir": true, 43 "IsRelative": false, 44 "Value": "dev" 45 }, 46 { 47 "Exists": false, 48 "IsDir": false, 49 "IsRelative": false, 50 "Value": "foobar" 51 } 52 ] 53 ``` 54 55 ## Supported Hooks 56 57 * `Marshal()` 58 Supported 59 * `ReadArray()` 60 Each element is a directory branch. Root, `/`, is treated as it's own element 61 * `ReadArrayWithType()` 62 Same as `ReadArray()` 63 * `ReadIndex()` 64 Returns a directory branch or filename if last element is a file 65 * `ReadMap()` 66 Not currently supported 67 * `ReadNotIndex()` 68 Supported 69 * `Unmarshal()` 70 Supported 71 * `WriteArray()` 72 Each element is a directory branch 73 74 ## See Also 75 76 * [MUREX_EXE](../variables/murex_exe.md): 77 Absolute path to running shell 78 * [PWD](../variables/pwd.md): 79 Current working directory 80 * [PWDHIST](../variables/pwdhist.md): 81 History of each change to the sessions working directory 82 * [`paths`](../types/paths.md): 83 Structured array for working with `$PATH` style data 84 85 ### Read more about type hooks 86 87 - [`ReadIndex()` (type)](../apis/ReadIndex.md): Data type handler for the index, `[`, builtin 88 - [`ReadNotIndex()` (type)](../apis/ReadNotIndex.md): Data type handler for the bang-prefixed index, `: Read from a data type one array element at a time 90 - [`WriteArray()` (type)](../apis/WriteArray.md): Write a data type, one array element at a time 91 - [`ReadMap()` (type)](../apis/ReadMap.md): Treat data type as a key/value structure and read its contents 92 - [`Marshal()` (type)](../apis/Marshal.md): Converts structured memory into a structured file format (eg for stdio) 93 - [`Unmarshal()` (type)](../apis/Unmarshal.md): Converts a structured file format into structured memory 94 95 <hr/> 96 97 This document was generated from [builtins/types/paths/path_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/types/paths/path_doc.yaml).