RefrEnv
RefrEnv copied to clipboard
[Feature Request] add RefrEnv_ResetPath to reset the path and RefrEnv_ResetEverything to reset everything
I am having trouble refreshing my environment variable after using RefrEnv.bat.
I use the following PowerShell script to remove specific directories from my USER PATH environment variable:
$paths2delete = @(
'C:\Users\PC\AppData\Local\Programs\Python\Python311;',
'C:\Users\PC\AppData\Local\Programs\Python\Python311\Scripts;'
)
$systemPath = [Environment]::GetEnvironmentVariable('Path', 'User')
foreach ($path in $paths2delete) {
$systemPath = $systemPath.replace($path, '')
}
$systemPath = $systemPath -split ';' | Where-Object { $_ -ne '' }
$systemPath = $systemPath -join ';'
[Environment]::SetEnvironmentVariable('Path', $systemPath, 'User')
Write-Host "Deleted from path!"
Write-Host $systemPath
Steps to Reproduce:
- Have these paths in your user path variable at the start
C:\Users\PC\AppData\Local\Programs\Python\Python311; C:\Users\PC\AppData\Local\Programs\Python\Python311\Scripts;
- Open Command Prompt (Window 1) and leave it open.
- Open another Command Prompt (Window 2) and run the following command to execute the PowerShell script above:
or just mouse2 click on Remove-Python311.ps1 and select "Run with Powershell" to remove the two Python 3.11 paths from your user path variable.powershell -command "& '.\Remove-Python311.ps1'"
- Manually check the USER PATH environment variable using the Windows Environment Variables manager to make sure they are removed correctly.
- Switch back to Command Prompt (Window 1) and run
RefrEnv.bat
.
Observed Behavior:
After running RefrEnv.bat
in Window 1, the removed paths reappear at the end of the PATH variable, separated by an empty line, as shown below:
echo %path:;=&echo(%
C:\Program Files\ffmpeg\bin
C:\Program Files\ImageMagick
C:\Users\PC\AppData\Roaming\npm
C:\Users\PC\go\bin
C:\Users\PC\AppData\Local\Programs\Ollama
C:\Users\PC\AppData\Local\Programs\Python\Python311
C:\Users\PC\AppData\Local\Programs\Python\Python311\Scripts
Expected Behavior:
The paths C:\Users\PC\AppData\Local\Programs\Python\Python311
and C:\Users\PC\AppData\Local\Programs\Python\Python311\Scripts
should be completely removed from the PATH variable.
Questions:
Am I doing something wrong, or is there an additional step needed to ensure that the PATH environment variable is updated correctly after using RefrEnv?