How put path changing .bat file inside %PATH%?

1

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 ;)

wojciechowskip

Posted 2013-10-22T22:56:58.320

Reputation: 53

Answers

1

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.

Debra

Posted 2013-10-22T22:56:58.320

Reputation: 4 000

Thank you! Your solution (mklink's way) is close enough to what I need. – wojciechowskip – 2013-10-23T16:53:08.303

0

As the other poster stated "~" is a *nix thing. Windows doesn't have a similar convention that I am aware of.

Path command can be set in the command prompt using the "set" command, but I don't think that is what you are looking for either. What that does is gives the command prompt a list of places to check when you execute a command. say you type in "pkunzip" and it looks through all the paths specified in "PATHS" to find the executable. It isn't really used much anymore and was more of a DOS thing.

BUT.... you can still use it as a shortcut...

if you do something like

set somepath=c:\somefolder\somefolder

Then when you want to reference it you could do

dir %somepath%

You can set a list of all the "set" environment variables by typing "set" at the command prompt.

Does this help at all? Maybe I don't understand your question.

MikeAWood

Posted 2013-10-22T22:56:58.320

Reputation: 647

Hi, thanks for your response and clear description of usage. However, using % symbols is not acceptable in my case. Debra's post contains everything I need ;) – wojciechowskip – 2013-10-23T17:00:54.700