更改Windows命令提示符以仅显示当前文件夹

时间:2017-06-09 21:31:33

标签: windows batch-file command-prompt

而不是显示

C:\Users\test_user\Documents\Folder\etc

显示

\etc

或者如果可能的话将其限制为一定数量

\Document\Folder\etc

5 个答案:

答案 0 :(得分:0)

简而言之,无法看到一种简单的方法。 要更改提示选项,可以使用prompt命令。您未查找的配置未列出。 可以查看可用选项 提示/?在命令窗口中。

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prompt.mspx?mfr=true

答案 1 :(得分:0)

如果您签入帮助prompt /?,则有两个选项可以显示当前驱动器或完整路径。

我建议与Drive一起使用换行选项,以便使用以下组合获得更多空间来查看/键入命令。

prompt $P$_$G

通过此操作,您将能够在提示上方的行中看到路径。

答案 2 :(得分:0)

就像其他人指出的那样,您可以使用命令-prompt 设置以cmd显示的文本

虽然不能动态地仅将路径设置为父文件夹,但是可以使用以下方式手动设置路径:

prompt {text}

因此,您可以将其设置为:

prompt etc\$G

这将导致:

etc\>

$G添加一个箭头。您可以参考documentation以获得详细说明。

答案 3 :(得分:0)

以下是一个简单的批处理脚本,可以将提示设置为仅包括当前文件夹。请注意,它不适用于带有某些字符的目录名称,例如括号和空格。我将其命名为cdd.bat。

@echo off
cd %1

for %%i in (%CD%) do set NEWDIR=%%~ni
PROMPT %NEWDIR%$G

答案 4 :(得分:0)

这是一个.ps1文件,我用来为自己完成此操作。

<#
FileName: promptPsShort.ps1

To set the prompt to the last folder name in the path:
> function prompt {$l=Get-Location; $p="$l".split("\")[-1]; "PS $p> "}  
  # works at cmd prompt, BUT NOT DIREECTLY from a .ps1 file.

RESEARCH

1. google: powershell 7 copy text into clipboard
  [How to copy text from PowerShell](https://superuser.com/q/302032/236556)
  [Set-Clipboard](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/?view=powershell-7)
2. google: powershell escape double quote
  [Escaping in PowerShell](http://www.rlmueller.net/PowerShellEscape.htm)
3. google: powershell raw string
  [About Quoting Rules](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7)

4. Usage example: powershell
PS C:\flutter_beta\flutter\examples\catalog\android\app\src\main> pwd

Path
----
C:\flutter_beta\flutter\examples\catalog\android\app\src\main

PS C:\flutter_beta\flutter\examples\catalog\android\app\src\main> promptPsShort.ps1
Paste the current Clipboard contents into the Powershell Command Line and press Enter.
PS C:\flutter_beta\flutter\examples\catalog\android\app\src\main> function prompt {$l=Get-Location; $p="$l".split("\")[-1]; "PS $p> "}
PS main>
PS main>
PS main>

#>


$shortPromptCmdStr = @'
function prompt {$l=Get-Location; $p="$l".split("\")[-1]; "PS $p> "}
'@

Set-Clipboard -Value $shortPromptCmdStr

write-host "Paste the current Clipboard contents into the Powershell Command Line and press Enter."

爱与和平, 乔

相关问题