有没有办法在Windows中设置递归环境变量?

发布于 2024-10-19 05:42:44 字数 93 浏览 1 评论 0原文

我的保管箱中有一个应用程序目录 - 我希望能够从命令行访问所有这些目录,而无需设置路径变量的加载和加载。有没有办法设置递归路径变量?我尝试将 ** 放在最后 - 没有乐趣。

I have an apps directory in my dropbox - I'd like to be able to access all of them from the command line without having to set up loads and loads of path variables. Is there any way to set up a recursive path variable? I tried putting ** at the end - no joy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别把无礼当个性 2024-10-26 05:42:44

您不能在 PATH 环境变量中使用占位符或类似内容。它只是目录的串联,没有附加功能。

因此,要么将所有应用程序目录添加到 PATH 环境变量中,要么考虑其他方法来解决问题。例如,您可以将一个目录添加到 PATH 中,并在其中放置启动应用程序的应用程序名称的批处理文件。

You can't use placeholders or anything like that in the PATH environment variable. It's just a concatenation of directories, no additional features.

So either add all of the app directories to the PATHenvironment variable or think about other ways to solve the problem. For example, you could add one directory to the PATH and place batch files named like the apps there that start the apps.

御弟哥哥 2024-10-26 05:42:44

为这个11年前的问题注册了一个帐户。

    $path = Read-Host -Prompt "Enter the exact path that needs to be recursively added to the PATH env:"
    $items = gci -Path $path -Recurse -Directory -name
    $nuPath = $env:Path
    $r = 0
    write-Host "Env started as $nuPath"
    foreach ($iitem in $items){
    $addpath = ($path + "\" + $iitem)
    $executabledir = $addpath + '\' + "*.exe"
    if(test-path $executabledir){
    Write-Host $addpath
    $regexAddPath = [regex]::Escape($addPath)
    $arrPath = $nuPath -split ';' | Where-Object {$_ -notMatch "^$regexAddPath\\?"}
    $nuPath = ($arrPath + $addPath) -join ';'
    ++$r
    }
    }
    $result = ($path + ";" + $nupath) -join ';'
    $temp = New-TemporaryFile
    $result.ToString() > $temp
    Start-Process notepad.exe -ArgumentList $temp.FullName
    
    $title    = 'WARNING'
    $question = "Your new environmental variable for PATH will be in the notepad window that popped up. are you sure you want to continue?"
    $choices  = '&Yes', '&No'
    
    $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
    if ($decision -eq 0 -and $r -gt 5) {
        $title    = 'Are you really sure?'
        $question = 'This is larger than 5 entries and this can ruin your day if you mess it up. Just doublechecking everything is OK'
        $choices  = '&Yes', '&No'
    
        $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
            if ($decision -eq 0) {
            $env:Path > $HOME\pathbkup.txt
            [Environment]::SetEnvironmentVariable("Path", $result, "Machine")
            }
            else {
            Write-Host 'cancelled'
            }
    }
    else {
        Write-Host 'cancelled'
         }
    Remove-Item $temp

Made an account for this 11 year old question.

    $path = Read-Host -Prompt "Enter the exact path that needs to be recursively added to the PATH env:"
    $items = gci -Path $path -Recurse -Directory -name
    $nuPath = $env:Path
    $r = 0
    write-Host "Env started as $nuPath"
    foreach ($iitem in $items){
    $addpath = ($path + "\" + $iitem)
    $executabledir = $addpath + '\' + "*.exe"
    if(test-path $executabledir){
    Write-Host $addpath
    $regexAddPath = [regex]::Escape($addPath)
    $arrPath = $nuPath -split ';' | Where-Object {$_ -notMatch "^$regexAddPath\\?"}
    $nuPath = ($arrPath + $addPath) -join ';'
    ++$r
    }
    }
    $result = ($path + ";" + $nupath) -join ';'
    $temp = New-TemporaryFile
    $result.ToString() > $temp
    Start-Process notepad.exe -ArgumentList $temp.FullName
    
    $title    = 'WARNING'
    $question = "Your new environmental variable for PATH will be in the notepad window that popped up. are you sure you want to continue?"
    $choices  = '&Yes', '&No'
    
    $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
    if ($decision -eq 0 -and $r -gt 5) {
        $title    = 'Are you really sure?'
        $question = 'This is larger than 5 entries and this can ruin your day if you mess it up. Just doublechecking everything is OK'
        $choices  = '&Yes', '&No'
    
        $decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
            if ($decision -eq 0) {
            $env:Path > $HOME\pathbkup.txt
            [Environment]::SetEnvironmentVariable("Path", $result, "Machine")
            }
            else {
            Write-Host 'cancelled'
            }
    }
    else {
        Write-Host 'cancelled'
         }
    Remove-Item $temp
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文