Is there a Python library that takes a windows path and replaces expanded environment variables with environment variables?
For example:
C:\Users\Username\Documents\Text.txt -> %USERPROFILE%\Documents\Text.txt
C:\Windows\System32\cmd.exe -> %WINDIR%\System32\cmd.exe
C:\Program Files\Program\Program.exe -> %PROGRAMFILES%\Program\Program.exe
The best way to explain would be to get functionality that does the opposite of
os.path.expandvars('some path with environment variables')
Support for different languages would also be a requirement.
C:\Archivos de programa\Progra\Program.exe -> %PROGRAMFILES%\Program\Program.exe
%FOO%and%BAR%that both expand toC:\Windows, in that case which should I use?winshellmodule, specifically its Special Folders part that grabs some of the special folders. For the rest you'll have to use Win32 API. Then it's just a matter of checking if your path intersects with the special folder and replacing it with its canonical environment variable name - you can use theos.pathfacilities for that.