The best ways I can think of:
To query the default drive, issue the "CD" command with no
parameters, and capture the first two characters of its output
(drive letter and colon), e.g.
To query the current working directory on a specified drive,
issue the CD command with that drive as its parameter (e.g.
CD D:) and then capture its output.
Can anyone suggest a cleaner way?
- Rich
Your techniques seem reasonable.
@echo off
for /f "delims=" %%a in ("%cd%") do set "cntdrv=%%~da"
for /f "delims=" %%a in ('cd d:') do set "Ddir=%%~pnxa"
echo "%cntdrv%" "%ddir%"
pause
"Rich Pasco" <rich...@hotmail.com> wrote in message
news:%232lPcul...@TK2MSFTNGP06.phx.gbl...
Here is another way:
@echo off
echo The current drive is %cd:~0,2%
echo The current directory is %cd:~2%
Your cleaner way to find the current drive seems to be the one
I proposed (albeit a concise expression of it). Your statement
of the current directory shows only the current directory of the
default drive, whereas I asked for a way to find the current
directory of any specified drive. I was not able to make your
syntax work on a non-default drive, like this:
echo The current directory of drive e: is %cd e:%
- Rich
If you want the current directory of the specified drive then foxidrive's
method is the simplest way to go. A more involved method goes like this:
@echo off
pushd "%1"
echo Drive=%cd:~0,2%, Folder=%cd:~2%
popd
Wonderful. Thanks to both of you for all your help.
- Rich