I have a problem described here (you can read it for better understanding). I need to write .bat file that change path.
For example:
While sending a command in cmd: cd ~
I want to go to %HOMEPATH%. In fact - I just want to replace ~ by %HOMEPATH% in every command which include directories.
How can I achieve it? I read here that I must to put path changing .bat file inside %PATH%. How to do it? And how to code that path changing function in Windows scripting language?
Any advice would be appreciated ;)
Answer
If I understand your question correctly --
The command you want is "SETX", not SET. "SETX" will set an environment variable pervasively. Alternatively you can set environment variables through the GUI using Control Panel > System > Advanced System Settings > Environment Variables.
For what you want to do, you can use a command like:
SETX HP %USERPROFILE%
Then (in future command windows,not the current one) HP will be equal to the location of %USERPROFILE%, which is usually C:\USERS\ in Windows 7.
Then in the future, you can use CD %HP%
.
==========
Alternatively, you can create a symbolic link; however, symlinks will point to a specific location. For example, you can use
MKLINK /D HP C:\USERS\WOJ
and then the command CD HP
will take you to C:\USERS\WOJ
The problem with this method is that you have to be in the directory that holds the symlink to refer to it.
The constraint that you are running into is how Windows handles aliases. You can easily alias commands in Windows with DOSKEY, but locations cannot be similarly aliased, though they are referred to with environment variables (both system and user-specific). And environment variables require you to use delimiting % signs to do the replacement.
No comments:
Post a Comment