RefrEnv icon indicating copy to clipboard operation
RefrEnv copied to clipboard

[Feature Request] add RefrEnv_ResetPath to reset the path and RefrEnv_ResetEverything to reset everything

Open i486 opened this issue 9 months ago • 13 comments

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:

  1. 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;
  2. Open Command Prompt (Window 1) and leave it open.
  3. Open another Command Prompt (Window 2) and run the following command to execute the PowerShell script above:
    powershell -command "& '.\Remove-Python311.ps1'"
    
    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.
  4. Manually check the USER PATH environment variable using the Windows Environment Variables manager to make sure they are removed correctly.
  5. 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?

i486 avatar May 18 '24 18:05 i486