I would like to know how I check if a directory exists in Nushell?
CodePudding user response:
Use the path exists
builtin. Examples:
> "/home" | path exists
true
> "MRE" | path exists
false
> "./nu-0.71.0-x86_64-unknown-linux-gnu" | path exists
true
> [ '.', '/home', 'MRE'] | path exists
╭───┬───────╮
│ 0 │ true │
│ 1 │ true │
│ 2 │ false │
╰───┴───────╯
> if ([ '.', '/home', '/proc'] | path exists | reduce -f true { |it, acc| $acc and $it }) {
"All directories exists"
} else {
"One ore more directories are missing"
}
All directories exists
See help path exists
for more details and help path
for more path helper builtins.