Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: short prompt?

0 views
Skip to first unread message

Timo Salmi

unread,
Apr 28, 2006, 6:00:24 AM4/28/06
to
sali wrote:
> is it possible to cd to short-named dir, but prompt to show full, long name?

The question essentially is, when in a short-named folder, how can
one get its long name? The solution below should do this, for XP at
least

@echo off & setlocal enableextensions
cd C:\DOCUME~1
for /f %%d in ("%cd%") do set name_=%%~nd
for /f "tokens=* delims=" %%a in (
'dir /x ..^|find "%name_%"') do set long_=%%a
set long_=%long_:~49%
echo %long_%
endlocal & goto :EOF

The output would be
C:\DOCUME~1>c:\_d\test\cmdfaq
Documents and Settings

All the best, Timo

P.S. I have set the followups to the more active alt.msdos.batch.nt

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

Timo Salmi

unread,
Apr 28, 2006, 6:35:45 AM4/28/06
to
Timo Salmi wrote:
> The question essentially is, when in a short-named folder, how can
> one get its long name? The solution below should do this, for XP at
> least

More generally:

@echo off & setlocal enableextensions

echo.
echo +----------------------------------------------------+
echo : Get the long name of a short-named folder or file :
echo : By Prof. Timo Salmi. Last modified Fri 28-Apr-2006 :
echo +----------------------------------------------------+
echo.
::
:: Usage
if "%~1"=="" (
echo Usage: %~f0 "ShortFolderOrFileName"
goto :EOF
)
::
:: Check that it is about a short name
echo "%~1"|find "~">nul
if %errorlevel% GTR 0 (
echo "%~1" is not a valid short name
goto :EOF
)
::
:: Check the existence
if not exist "%~1" (
echo "%~1" not found
goto :EOF
)
::
:: Get and process the information
for /f %%d in ("%~1") do set name_=%%~nd
for /f %%p in ("%~1") do set path_=%%~dpp


for /f "tokens=* delims=" %%a in (

'dir /x "%1\.."^|find "%name_%"') do set long_=%%a
set long_=%long_:~49%
::
:: Show the results
echo %~1
echo %path_%%long_%
endlocal & goto :EOF

The output might be e.g.
C:\_M>c:\_d\bas\cmdfaq "C:\_D\BAS\KOE2~1.CMD"
C:\_D\BAS\KOE2~1.CMD
C:\_D\BAS\KOE 2.CMD

All the best, Timo

Todd Vargo

unread,
Apr 28, 2006, 11:01:55 AM4/28/06
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:e2sp3o$o7h$1...@saavi.uwasa.fi...

> sali wrote:
> > is it possible to cd to short-named dir, but prompt to show full, long
name?
>
> The question essentially is, when in a short-named folder, how can
> one get its long name? The solution below should do this, for XP at
> least
>
> @echo off & setlocal enableextensions
> cd C:\DOCUME~1
> for /f %%d in ("%cd%") do set name_=%%~nd
> for /f "tokens=* delims=" %%a in (
> 'dir /x ..^|find "%name_%"') do set long_=%%a
> set long_=%long_:~49%
> echo %long_%
> endlocal & goto :EOF
>
> The output would be
> C:\DOCUME~1>c:\_d\test\cmdfaq
> Documents and Settings
>
> All the best, Timo
>
> P.S. I have set the followups to the more active alt.msdos.batch.nt

Nice code. Note, without /AD, the output contains file names as well as
directory names. If the directory is large, the capture could be slow. There
is also a small (remote) possibility that the SFN could be found embedded in
one of the LFNs preceding the actual SFN sought.

ATTRIB cuts right to the point. The following untested code is based on
output from ATTRIB in Windows 98 therefore, the ~27 may need modified.

@echo off & setlocal enableextensions
cd C:\DOCUME~1

for /f "delims=" %%a in (
'attrib %cd%') do set long_=%%a
set long_=%long_:~27%
prompt %long_%
endlocal & goto :EOF

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Timo Salmi

unread,
Apr 28, 2006, 11:37:33 AM4/28/06
to
Todd Vargo <tlv...@sbcglobal.netz> wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote in message
>> The question essentially is, when in a short-named folder, how
>> can one get its long name? The solution below should do this,
>> for XP at least

> Nice code. Note, without /AD, the output contains file names as
> well as directory names.

True. In fact, that generic sfn to lfn conversion may be the more
useful outcome, even if strictly not the original question.

> ATTRIB cuts right to the point. The following untested code is
> based on output from ATTRIB in Windows 98 therefore, the ~27 may
> need modified.

> 'attrib %cd%') do set long_=%%a

That is an excellent catch, Todd. Appreciated. Much simpler than
mine. It indeed then is this simple to display the current folder's
long name:

C:\DOCUME~1>attrib %cd%
C:\Documents and Settings

All the best, Timo

--

Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Timo Salmi

unread,
Apr 28, 2006, 12:04:17 PM4/28/06
to
Todd Vargo <tlv...@sbcglobal.netz> wrote:
> The following untested code is based on output from ATTRIB in
> Windows 98 therefore, the ~27 may need modified.

@echo off & setlocal enableextensions

if "%~1"=="" (
set dir_=%cd%
) else (
set dir_=%~1
)
::
if not exist %dir_%\ (
echo "%dir_%" no such folder
goto :EOF)
::
for /f "tokens=* delims=" %%d in (
'attrib "%dir_%"') do set long_=%%d
set long_=%long_:~11%
::
echo %dir_%


echo %long_%
endlocal & goto :EOF

The output might be e.g.
C:\_M>C:\_D\BAS\CMDFAQ C:\DOCUME~1
C:\DOCUME~1
C:\Documents and Settings

All the best, Timo

--

Todd Vargo

unread,
Apr 28, 2006, 2:23:09 PM4/28/06
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:e2tee1$2un$1...@saavi.uwasa.fi...

> Todd Vargo <tlv...@sbcglobal.netz> wrote:
> > The following untested code is based on output from ATTRIB in
> > Windows 98 therefore, the ~27 may need modified.
>
> @echo off & setlocal enableextensions
> if "%~1"=="" (
> set dir_=%cd%
> ) else (
> set dir_=%~1
> )
> ::
> if not exist %dir_%\ (

Consider, %~1 is being used to remove user quoting, one might also expect a
user to also include spaces. Without quoting "%dir_%\", that would break the
IF NOT EXIST condition. In otherwords, you need to quote %dir_%\ to test it.

Timo Salmi

unread,
Apr 28, 2006, 4:13:20 PM4/28/06
to
Todd Vargo <tlv...@sbcglobal.netz> wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote in message
>> if "%~1"=="" (
>> set dir_=%cd%
>> ) else (
>> set dir_=%~1
>> )
>> ::
>> if not exist %dir_%\ (

> Consider, %~1 is being used to remove user quoting, one might also expect a
> user to also include spaces.

True in practice, if the script is misused (the code documentation
is not clear enough about %~1 being the short name). But in
principle, if used right, the short names have no spaces in them.

> Without quoting "%dir_%\", that would break the
> IF NOT EXIST condition. In otherwords, you need to quote %dir_%\ to test it.

Better indeed to introduce the quotes despite my comment above.
Thanks.

0 new messages