0

I know that the PROMPT command can be used to alter the command prompt but sometimes the directory path gets too long. Most of the time I'm not interested in the entire directory, just the last folder (leaf). Is there any way of shortening it?

marked as duplicate by duDE, DavidPostill windows Nov 16 '18 at 22:06

This question was marked as an exact duplicate of an existing question.

  • Alter prompt. You may alter it freely, until remove any char from it at all. For example, use prompt $P$_$G command. To make this setting permanent create the variable in user's environment with the value you need (MyComputer-RightClick-Properties-Additionally-Environ-UserEnviron-Create, name=prompt, value=needed_value). – Akina Nov 16 '18 at 9:53
  • Full list of prompt options here docs.microsoft.com/en-us/windows-server/administration/… – spikey_richie Nov 16 '18 at 10:18
0

Prompt does not support listing only the current folder, nor does prompt support querying environmental variables.

So even though the following command is possible, it does not work as desired:

prompt %cd:~-20%$G

The above command will show the right 20 characters of the path, and would appear to be the best solution... except, when you change path, the string stays exactly the same.

So that doesn't work. Prompt does not have other options to specify just the last folder in a path.

But the reason most people want this, is because on a long path, the cursor starts at the very end of the screen which makes typing commands a bit hard.

There are a few solutions to work with this problem.

  1. Don't use long paths, and if you have to, create junctions so you can create a shortcut to a lower path, so the path itself becomes shorter.

For example, you have C:\Program Files (x86)\Microsoft Office\Office16\Root and you want to have this folder accessible as a short path, you could do the following:

md c:\links
cd /d c:\links
mkdir /j "C:\Program Files(x86)\Microsoft Office\Office16\Root" Office

Administrative rights on the command prompt are required to create symbolic links.

If you now go to c:\links\office, you end up on the office folder, but on your harddisk the files remain on the original folder.

  1. Increase the size of your command prompt window.

You can just increase the command prompt window in amount of colums and rows and more will fit on your screen, including longer paths.

  1. Alter the prompt to place the cursor on the next row. No matter how long the path is, your cursor always ends up at the same spot, so typing commands will not have interference of the long path.

You could write your prompt as follows:

C:\>prompt $P_$G

C:\
>_

or C:>prompt $P$G_

C:\>
_

Once you are happy with the changes of the command prompt, you can commit your changes by typing the following:

setx prompt %prompt%

Not the answer you're looking for? Browse other questions tagged or ask your own question.