1.

Solve : Set DOS prompt to dir name?

Answer»

The is a Unix prompt setting whereby the prompt can always show the working directory name - not the full path, that is, just the name.

This doesn't appear to be AVAILABLE in DOS using prompt, or any of it's associated variables (correct me if I'm wrong). However, I assume it would be possible to write a small batch file that could do this.

I have spent a while doing this, but without MUCH luck since I don't know how to do the string manipulation required.

Could someone help me out ?You didn't mention your OS so I wrote this for XP.

CODE: [Select]
@echo off
if .%1==. for /f "tokens=1-5 delims=:\" %%a in ("%cd%") do (%0 %%a %%b %%c %%d %%e)
:next
if .%2==. set prompt=%1 & goto :eof
shift
goto next



It works for up to 5 levels of directories, but you can change that easily enough. I'll leave what practical application this has up to you.

Thanks for the help, Sidewinder.

I should have been more specific in a couple of places..

My OS is Win 2000.

I was looking for a script that I could use as a replacement command for CD. Let's call it DD. This script would perform the same function as CD, but would also change the prompt each TIME to the new current dir's name
- I like to know where I am, but don't really want the prompt filled up with the whole path.

Your script was most of the way there. It only fell short in a couple of places

1) It didn't change the working directory (my fault for not specifying). This was easily SOLVED by adding the line: CD %1 as line 2.

2) It seemed to be using the input argument for the prompt. So DD sub\subsub would leave me with the prompt: sub\subsub.

I wrestled for a good while. I still can't work out what goes on inside FOR loops. In the end I went off and hunted down a different construction for getting the folder name, and managed to fiddle with it to create the desired new command.

Here 'tis:

Code: [Select]@echo off
cd %1

Call :FOLDER "%CD%"
prompt %myCurDir%$G$_

:FOLDER
Set MyCurDir=%~n1

Thanks



Discussion

No Comment Found