上传文件至 /
Signed-off-by: Zengtudor <zengtudor@outlook.com>
This commit is contained in:
commit
be3e010af0
31
add_path.ps1
Normal file
31
add_path.ps1
Normal file
@ -0,0 +1,31 @@
|
||||
# 获取当前脚本所在的目录
|
||||
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
# 读取 env.txt 文件中的每一行
|
||||
$envFile = Join-Path $scriptPath "env.txt"
|
||||
if (Test-Path $envFile) {
|
||||
$paths = Get-Content $envFile | ForEach-Object {
|
||||
# 转换为绝对路径
|
||||
Join-Path $scriptPath $_
|
||||
}
|
||||
|
||||
# 保存原始的 PATH 环境变量
|
||||
$originalPath = $env:PATH
|
||||
|
||||
# 将路径添加到 PATH 的开头
|
||||
foreach ($path in $paths) {
|
||||
$env:PATH = "$path;$env:PATH"
|
||||
}
|
||||
|
||||
Write-Host "以下路径已添加到 PATH 的前面:"
|
||||
$paths | ForEach-Object { Write-Host $_ }
|
||||
|
||||
# 启动一个新的 PowerShell 会话,并传递修改后的 PATH 环境变量
|
||||
$newEnvPath = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
|
||||
|
||||
Start-Process powershell -ArgumentList "-NoExit", "-Command", "echo '继承了修改后的 PATH 环境变量';`$env:PATH='$newEnvPath';"
|
||||
|
||||
Write-Host "已打开一个新的 PowerShell 会话,继承了修改后的环境变量。"
|
||||
} else {
|
||||
Write-Host "未找到 env.txt 文件,请检查文件是否存在。"
|
||||
}
|
Loading…
Reference in New Issue
Block a user