gpt4 book ai didi

powershell - PowerShell:将每个子目录添加到路径

转载 作者:行者123 更新时间:2023-12-03 01:26:42 25 4
gpt4 key购买 nike

在Windows 10上以及通过PowerShell,如何将每个子目录添加到PATH变量中?

我为Linux调整了一些方法(例如this one),然后将它们“适配”到PowerShell,我遇到了以下问题。

'$env:PATH = $env:PATH + (find C:\Users\appveyor\ -type d -printf "\";%pbuild\\"")'

这抛出 The filename, directory name, or volume label syntax is incorrect.
还有一点上下文:我正在appveyor上运行它,并试图将 appveyor下的 C:\Users\appveyor\*\build\(为简化起见)添加到路径中。

最佳答案

Linux上的find命令与Windows上的Find命令非常不同。

在您的情况下,我将在PowerShell中使用Get-ChildItem(也可以通过别名gcidirls来使用)返回目录对象数组,并将其添加到转换为数组的当前路径中,然后使用Windows路径分隔符,是分号-join

可能看起来像这样:

$env:PATH = (
@($env:PATH) + (
Get-ChildItem -LiteralPath 'C:\Users\appveyor' -Directory -Recurse
)
) -join [System.IO.Path]::PathSeparator # <- that could just be a literal string ';'

关于powershell - PowerShell:将每个子目录添加到路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62143066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com