How can I shorten the path of a DOS prompt?

不想你离开。 提交于 2019-11-28 19:53:13

问题


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>

回答1:


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




回答2:


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

>



回答3:


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




回答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?"



来源:https://stackoverflow.com/questions/18391932/how-can-i-shorten-the-path-of-a-dos-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!