paolof89
paolof89

Reputation: 1369

How to reduce the current directory path in Windows command prompt

What is the command to reduce the current path in the windows command prompt?

For example when I work in a subfolder I don't want to see the entire path from the root

I don't want to see: C:\Users\myuser\AppData\Local\conda\conda\pkgs> but just: > or pkgs>

Upvotes: 1

Views: 3550

Answers (2)

David Maisonave
David Maisonave

Reputation: 188

Here are some options:

  • [Option 1.A] Change the prompt with following command: prompt $p$_$g

    • That will cause the full path to be displayed right before a short command prompt.
      C:\Users\david\AppData\Roaming\Notepad++
      >cd ..
      
      C:\Users\david\AppData\Roaming
      >cd "Notepad++\plugins"
      
      C:\Users\david\AppData\Roaming\Notepad++\plugins
      >
      
  • [Option 1.B] If you like [Option 1.A], you can make it permanent by creating an environmental variable called PROMPT and set the value to $p$_$g

    • You can set the environmental variable using the following steps:
      • Press Win+I or click on settings from the Start button.
      • Enter View Advanced system settings in the search field.
      • Click on View Advanced system settings
      • Select the Advanced tab
      • Click on the Environment Variables button located at the bottom right side.
      • If you want to add this option just for yourself, click [New] button in User variables. If it should be applied to all users, click [New] in the System variables.
      • Set the variable name to PROMPT
      • Set the variable value to $p$_$g
    • After creating the environmental variable, open a new DOS window, and it should get the new prompt settings automatically.
  • [Option 2] Set the prompt with command:prompt $n$$$g

    • That will give this type of prompt:C$> Where it only includes the drive letter in the prompt.
    • Any time you need to now the path, just enter command CD
      C$>cd
      C:\Users\david\.VirtualBox
      
      C$>
      
    • If you like this option, use steps in [Option 1.B] to make it permanent.
  • [Option 3] To include only the last directory in the DOS prompt, a batch file (PromptDir.bat) can be created with the following content:

    @ECHO OFF
    FOR %%I IN (.) DO Prompt %%~nI%%~xI$G
    
    • When running a DOS window, call the batch file (PromptDir.bat)
      • Here's an example how the prompt will change after running PromptDir
        C:\Users\david\AppData\Roaming\Notepad++>PromptDir
        
        Notepad++>
        
    • Make sure to put this file in a path included in the %path% environmental variable. (ie C:\Windows\system32)
    • To get back the normal prompt, just enter command PROMPT
    • The downside to this method is that the prompt doesn't change when the directory changes. You would need to call the batch file each time you want the prompt to display the changed path.
  • [Option 4] This method includes most of the above options in one batch file, where the user can select which method to apply by passing 1, 2, or 3. If no argument is passed, then the prompt gets reset.

    • Create a file called (Prompt_.cmd) with the below text.
      @ECHO OFF
      IF "%~1" equ "1"  goto :FullPathAboveShortPrompt
      IF "%~1" equ "2"  goto :ShortPrompt
      IF "%~1" equ "3"  goto :LastDirPrompt
      prompt
      Goto :eof
      
      :FullPathAboveShortPrompt
      prompt $p$_$g
      Goto :eof
      
      :ShortPrompt
      prompt $g
      Goto :eof
      
      :LastDirPrompt
      FOR %%I IN (.) DO Prompt %%~nI%%~xI$G
      Goto :eof
      
    • Copy the file to a path in the %path% environmental variable. (ie C:\Windows\system32)
    • Example usage:
      • Prompt_ 1
      • Prompt_ 2
      • Prompt_ 3
      • Prompt_

Upvotes: 3

Glenn G
Glenn G

Reputation: 667

while you can't change the command prompt to only show the current directory, you can change it to only be the greater than symbol > by using the following command at the prompt

prompt = $G

for more information you can use the command prompt /? or check https://technet.microsoft.com/en-us/library/bb490977.aspx

Upvotes: 4

Related Questions