如何在 Nushell 脚本中检查目录是否存在?

6
我想知道如何在Nushell中检查目录是否存在?
1个回答

8
使用内置的path exists。 示例:
> "/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

请查看help path exists以获取更多详细信息,并查看help path以获取更多路径帮助内置函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接