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?

phuclv
  • 30,396
  • 15
  • 136
  • 260

1 Answers1

2

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%
LPChip
  • 66,193