首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查Nushell脚本中是否存在目录?

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

Stack Overflow用户
提问于 2022-11-22 13:43:14
回答 1查看 30关注 0票数 1

我想知道如何检查Nushell中是否存在目录?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-22 16:14:39

使用path exists内置。示例:

代码语言:javascript
复制
> "/home" | path exists
true
代码语言:javascript
复制
> "MRE" | path exists
false
代码语言:javascript
复制
> "./nu-0.71.0-x86_64-unknown-linux-gnu" | path exists
true
代码语言:javascript
复制
> [ '.', '/home', 'MRE'] | path exists
╭───┬───────╮
│ 0 │ true  │
│ 1 │ true  │
│ 2 │ false │
╰───┴───────╯
代码语言:javascript
复制
> 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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74533599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档