jingyang81
jingyang81

Reputation: 473

How can I shorten the path of a DOS prompt?

My path on my DOS prompt is ridiculously long. How can I shorten this?

C:\RUBY\Ruby_Practice\prep-work-master\coding-test-2\practice-problems\spec>

Upvotes: 37

Views: 25946

Answers (4)

Here is a .bat file that displays the prompt with the final folder name in the current dir path.

for %%* in (.) do set CurrDirName=%%~nx*
echo %CurrDirName%
prompt %CurrDirName% $G

Lines 1 and 2 come from This answer to SuperUser: "How can I find the short path of a Windows directory/file?"

Upvotes: 3

Jiminion
Jiminion

Reputation: 5168

Right-click on My Computer|Properties. Then from the Advanced Tab, click Environment Variables, then add a new User Variable called PROMPT and set it to $p$_$+$g.

http://www.hanselman.com/blog/ABetterPROMPTForCMDEXEOrCoolPromptEnvironmentVariablesAndANiceTransparentMultiprompt.aspx

Upvotes: 39

RamValli
RamValli

Reputation: 4485

In addition to the @Daniel's answer, if you want to go back to the normal state, You can type prompt (without any arguments) and press Enter

It's not related to the question exactly, but i find it more useful to this scenario. When we use this prompt $G, this changes the command prompt path to >. Even when you navigate to the sub folders, the prompt will still remain as > which is not much useful.

Rather than doing this, we can map the most used path to a virtual drive. like C:\Users\ram\Desktop\temp to a virtual drive X:. By this way, you need not to see the unneeded path, as well as you can see the sub folder navigations like X:\subfolder>.

This is more useful to map your project to a virtual drive and do all the operations.

To Map a path to a virtual Drive

1) type subst [Drive:] [path] Example: cmd>subst X: C:\Users\ram\Desktop\temp

2) Then go to the drive by typing X: and Enter

To back to the earlier mode, you can just type the corresponding drive letter. In this case C: and Enter

Upvotes: 15

Daniel Ellis
Daniel Ellis

Reputation: 1219

To remove the path from the prompt use 'prompt $g' which will just show the chevron. You can then use the 'cd' command anytime to see the directory you are in. E.g.

C:\Windows\System32\drivers\etc>prompt $g
>
>cd
C:\Windows\System32\drivers\etc

>

Upvotes: 86

Related Questions