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

Bug with %%~sA resolved

1,362 views
Skip to first unread message

foxidrive

unread,
Mar 19, 2004, 5:19:12 AM3/19/04
to

You know the bug when using %%~sa to resolve a filename to the short path
which returns more than just the short filename? It is kinda erratic but
as example is as follows, with %%~sa and followed by %%~fa

D:\TEMPFO~1\0_3_BI~1.JPGg name\0=3=biz.jpg
D:\tempfolder with a long name\0=3=biz.jpg

After encountering it again I (re?)discovered that running command.com in
the batch file forces %%~sa to return the correct name - but it breaks
%%~fa.

It's an oddity, perhaps useful in some situations, but there you go.


@echo off
md "tempfolder with a long name"
cd "tempfolder with a long name"
type nul>"0=3=biz.jpg"
:: type nul>"0 test.jpg"
echo Short name (with bug) and longname
call :test
echo.
echo.running command.com
command /c rem
echo.exiting from command.com
echo.
echo Short name corrected and longname (with path bug)
call :test
cd ..
echo.
pause
rd /s /q "tempfolder with a long name"
goto :EOF
:test
for %%a in (0*.*) do echo %%~sa &echo %%~fa


While searching google groups for previous messages concerning the short
name bug I came across this message from Walter Zackery, Subject: Windows
NT tricks, traps and undocumented features, which I found interesting
reading from 'history'. URL is on one line.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=7s8dru%245gmu%241%40newssvr04-int.news.prodigy.com&rnum=4

Ted Davis

unread,
Mar 19, 2004, 9:02:02 AM3/19/04
to
On Fri, 19 Mar 2004 10:19:12 GMT, foxidrive <foxi...@Shotmail.com>
wrote:

>
>You know the bug when using %%~sa to resolve a filename to the short path
>which returns more than just the short filename? It is kinda erratic but
>as example is as follows, with %%~sa and followed by %%~fa
>
>D:\TEMPFO~1\0_3_BI~1.JPGg name\0=3=biz.jpg
>D:\tempfolder with a long name\0=3=biz.jpg
>
>After encountering it again I (re?)discovered that running command.com in
>the batch file forces %%~sa to return the correct name - but it breaks
>%%~fa.
>
>It's an oddity, perhaps useful in some situations, but there you go.

People who use command delimiters in filenames for use at the command
prompt instead of just in the GUI deserve all the weird behavior they
find. The commented out file creation of a valid name file indicates
you were fully aware that the problem was with the highly questionable
file name you actually used.

T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

OOTANI TAKASHI

unread,
Mar 20, 2004, 3:54:10 PM3/20/04
to
foxidrive <foxi...@Shotmail.com> writes:
> You know the bug when using %%~sa to resolve a filename to the short path
> which returns more than just the short filename? It is kinda erratic but
> as example is as follows, with %%~sa and followed by %%~fa
>
> D:\TEMPFO~1\0_3_BI~1.JPGg name\0=3=biz.jpg
> D:\tempfolder with a long name\0=3=biz.jpg

I think this bug may be serious.
The odd example filenames were made by Mr.foxidrive to explain the bug,
so some people may think that bug does not appear in real situation.

But I have a file "C:\Program Files\Common Files\System\Ole DB\msdadc.dll"
in my WinXPhome+Office2K, and another a lot of similar files.

@echo off
for %%A in ("C:\Program Files\Common Files\System\Ole DB\msdadc.dll") do (
echo %%~fA&echo %%~sA)

Results is:
C:\Program Files\Common Files\System\Ole DB\msdadc.dll
C:\PROGRA~1\COMMON~1\System\OLEDB~1\msdadc.dlldll

Of cource I don't think this bug raise errors in ordinary use of Windows,
but the bug may appear in custom made BAT/CMD scripts.

> After encountering it again I (re?)discovered that running command.com in
> the batch file forces %%~sa to return the correct name - but it breaks
> %%~fa.

I think this is a *feature* not a bug.

Befor running command.com, current directory is
"C:\work\tempfolder with a long name"
After running command.com, current directory is
"C:\work\TEMPFO~1"

The description of %~fI in for/? is
"expands %I to a fully qualified path name"
I think Microsoft will say "It does not assure that %~fI is always LFN".

Add PUSHD and POPD to your example, then the result is same befor COMMAND.COM.

> @echo off
> md "tempfolder with a long name"
> cd "tempfolder with a long name"
> type nul>"0=3=biz.jpg"
> :: type nul>"0 test.jpg"
> echo Short name (with bug) and longname
> call :test
> echo.
> echo.running command.com

ECHO CD=%CD%
PUSHD .
> command /c rem
ECHO CD=%CD%
POPD


> echo.exiting from command.com
> echo.
> echo Short name corrected and longname (with path bug)
> call :test
> cd ..
> echo.
> pause
> rd /s /q "tempfolder with a long name"
> goto :EOF
> :test
> for %%a in (0*.*) do echo %%~sa &echo %%~fa

> While searching google groups for previous messages concerning the short
> name bug I came across this message from Walter Zackery, Subject: Windows
> NT tricks, traps and undocumented features, which I found interesting
> reading from 'history'. URL is on one line.
>
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=7s8dru%245gmu%241%40newssvr04-int.news.prodigy.com&rnum=4

This URL's article is too long English page for me, so I haven't read yet.
I'm sorry if what I've written above was described in this article.
--
tksotn from JP

Todd Vargo

unread,
Mar 20, 2004, 7:03:25 PM3/20/04
to

"OOTANI TAKASHI" <tks...@anet.ne.jp> wrote in message
news:u7jxf9...@anet.ne.jp...

If I understand foxidrive correctly, the bug with %%sA only occurs in
CMD.EXE and the bug with %%fA only occurs with COMMAND.COM. I can not verify
this right now myself, so I'll ask foxidrive to confirm or clarify.

--
Todd Vargo (remove hyphen to reply by email)

foxidrive

unread,
Mar 20, 2004, 8:05:59 PM3/20/04
to
On Sun, 21 Mar 2004 05:54:10 +0900, OOTANI TAKASHI wrote:

> foxidrive <foxi...@Shotmail.com> writes:
>> D:\TEMPFO~1\0_3_BI~1.JPGg name\0=3=biz.jpg
>> D:\tempfolder with a long name\0=3=biz.jpg
>

> The odd example filenames were made by Mr.foxidrive to explain the bug,
> so some people may think that bug does not appear in real situation.

> But I have a file "C:\Program Files\Common Files\System\Ole DB\msdadc.dll"
> in my WinXPhome+Office2K, and another a lot of similar files.
>
> @echo off
> for %%A in ("C:\Program Files\Common Files\System\Ole DB\msdadc.dll") do (
> echo %%~fA&echo %%~sA)
>
> Results is:
> C:\Program Files\Common Files\System\Ole DB\msdadc.dll
> C:\PROGRA~1\COMMON~1\System\OLEDB~1\msdadc.dlldll

>> After encountering it again I (re?)discovered that running command.com in


>> the batch file forces %%~sa to return the correct name - but it breaks
>> %%~fa.
>
> I think this is a *feature* not a bug.

> Add PUSHD and POPD to your example, then the result is same befor COMMAND.COM.

I spent time trying to find a way around it breaking %%~fa, thanks for that
tip.

===[screen copy]===
Longname and Short name (with bug)

D:\tempfolder with a long name\a test.jpg
D:\TEMPFO~1\ATEST~1.JPGng name\a test.jpg

pushing current directory onto stack
running command.com
exiting from command.com
Long-name path is fubar but Short name bug squashed!

D:\TEMPFO~1\a test.jpg
D:\TEMPFO~1\ATEST~1.JPG

popping current directory from stack
The Name Behaviour restored as it was initially

D:\tempfolder with a long name\a test.jpg
D:\TEMPFO~1\ATEST~1.JPGng name\a test.jpg

===[/screen copy]===

@echo off
md "tempfolder with a long name"
cd "tempfolder with a long name"

type nul>"a test.jpg"
echo Longname and Short name (with bug)
call :test
echo.pushing current directory onto stack
pushd .


echo.running command.com
command /c rem
echo.exiting from command.com

echo.Long-name path is fubar but Short name bug squashed!
call :test
echo.popping current directory from stack
popd
echo.The Name Behaviour restored as it was initially
call :test
cd ..


pause
rd /s /q "tempfolder with a long name"
goto :EOF
:test

echo.
for %%a in (a*.*) do echo %%~fa &echo %%~sa
echo.


Todd Vargo said (in another message)


> If I understand foxidrive correctly, the bug with %%sA only occurs in
> CMD.EXE and the bug with %%fA only occurs with COMMAND.COM. I can not verify
> this right now myself, so I'll ask foxidrive to confirm or clarify.

Tood, both bugs are in CMD.EXE but are modified by the mere launching of
COMMAND.COM in the batch file.

foxidrive

unread,
Mar 20, 2004, 8:09:31 PM3/20/04
to
On Sun, 21 Mar 2004 05:54:10 +0900, OOTANI TAKASHI wrote:

> foxidrive <foxi...@Shotmail.com> writes:
>> D:\TEMPFO~1\0_3_BI~1.JPGg name\0=3=biz.jpg
>> D:\tempfolder with a long name\0=3=biz.jpg
>

> The odd example filenames were made by Mr.foxidrive to explain the bug,
> so some people may think that bug does not appear in real situation.

> But I have a file "C:\Program Files\Common Files\System\Ole DB\msdadc.dll"
> in my WinXPhome+Office2K, and another a lot of similar files.
>
> @echo off
> for %%A in ("C:\Program Files\Common Files\System\Ole DB\msdadc.dll") do (
> echo %%~fA&echo %%~sA)
>
> Results is:
> C:\Program Files\Common Files\System\Ole DB\msdadc.dll
> C:\PROGRA~1\COMMON~1\System\OLEDB~1\msdadc.dlldll

>> After encountering it again I (re?)discovered that running command.com in


>> the batch file forces %%~sa to return the correct name - but it breaks
>> %%~fa.
>
> I think this is a *feature* not a bug.

> Add PUSHD and POPD to your example, then the result is same befor COMMAND.COM.

I spent time trying to find a way around it breaking %%~fa, thanks for that
tip.

===[screen copy]===
Longname and Short name (with bug)

D:\tempfolder with a long name\a test.jpg
D:\TEMPFO~1\ATEST~1.JPGng name\a test.jpg

pushing current directory onto stack
running command.com
exiting from command.com
Long-name path is fubar but Short name bug squashed!

D:\TEMPFO~1\a test.jpg
D:\TEMPFO~1\ATEST~1.JPG

popping current directory from stack
The Name Behaviour restored as it was initially

D:\tempfolder with a long name\a test.jpg
D:\TEMPFO~1\ATEST~1.JPGng name\a test.jpg

===[/screen copy]===

@echo off


md "tempfolder with a long name"
cd "tempfolder with a long name"

type nul>"a test.jpg"
echo Longname and Short name (with bug)
call :test
echo.pushing current directory onto stack
pushd .

echo.running command.com
command /c rem
echo.exiting from command.com

echo.Long-name path is fubar but Short name bug squashed!
call :test
echo.popping current directory from stack
popd
echo.The Name Behaviour restored as it was initially
call :test
cd ..

pause
rd /s /q "tempfolder with a long name"
goto :EOF
:test

echo.
for %%a in (a*.*) do echo %%~fa &echo %%~sa
echo.


Todd Vargo said (in another message)
> If I understand foxidrive correctly, the bug with %%sA only occurs in
> CMD.EXE and the bug with %%fA only occurs with COMMAND.COM. I can not verify
> this right now myself, so I'll ask foxidrive to confirm or clarify.

Tood, both bugs make themselves felt in CMD.EXE but are modified by the

Todd Vargo

unread,
Mar 21, 2004, 11:23:53 PM3/21/04
to

"foxidrive" <foxi...@Shotmail.com> wrote:
> Todd Vargo said (in another message)
> > If I understand foxidrive correctly, the bug with %%sA only occurs in
> > CMD.EXE and the bug with %%fA only occurs with COMMAND.COM. I can not
verify
> > this right now myself, so I'll ask foxidrive to confirm or clarify.
>
> Tood, both bugs make themselves felt in CMD.EXE but are modified by the
> mere launching of COMMAND.COM in the batch file.

foxidrive, I follow you now, thanks. Unfortunately, I use Win95cmd in Win98
so the pushd/popd trick has no effect on my system. Although, Win98's
command.com returns 8.3 names correctly, I'm studying the %~s1 bug for
future reference.

Garry Deane

unread,
Mar 22, 2004, 4:17:59 AM3/22/04
to
On Fri, 19 Mar 2004 10:19:12 GMT, foxidrive <foxi...@Shotmail.com>
wrote:

>You know the bug when using %%~sa to resolve a filename to the short path


>which returns more than just the short filename? It is kinda erratic but
>as example is as follows, with %%~sa and followed by %%~fa
>
>D:\TEMPFO~1\0_3_BI~1.JPGg name\0=3=biz.jpg
>D:\tempfolder with a long name\0=3=biz.jpg
>
>After encountering it again I (re?)discovered that running command.com in
>the batch file forces %%~sa to return the correct name - but it breaks
>%%~fa.

<snip>

See this post for an explanation of the %~spi bug and a workaround
without using COMMAND.COM.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3d41032e.28814222%40192.168.0.2

Garry

foxidrive

unread,
Mar 22, 2004, 5:39:14 AM3/22/04
to

Sorry Garry, I can't manage to get the correct short path\filename using
the techniques you mention from that URL.

Garry Deane

unread,
Mar 23, 2004, 4:38:41 AM3/23/04
to
On Mon, 22 Mar 2004 10:39:14 GMT, foxidrive <foxi...@Shotmail.com>
wrote:

>> See this post for an explanation of the %~spi bug and a workaround
>> without using COMMAND.COM.
>>
>> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3d41032e.28814222%40192.168.0.2
>>
>> Garry
>
>Sorry Garry, I can't manage to get the correct short path\filename using
>the techniques you mention from that URL.

OK try this. The idea is to break up the LFN into its path/file
components and convert each separately. It's a bit more complex when
you have to also get the filename as a SFN.

@echo off
setlocal
set lfn="C:\Program Files\Common Files\System\Ole
DB\MSOrclOLEDBreadme.txt"
for %%a in (%lfn%) do set sfn=%%~sfa & set ln=%%~nxa
for %%a in (%sfn%) do set spn=%%~dpa
for %%a in (%spn%%ln%) do set sn=%%~snxa
echo [%spn%] [%sn%]

Garry

foxidrive

unread,
Mar 23, 2004, 5:18:48 AM3/23/04
to

Unfortunately this kind of file upsets it.

===[screen copy]===
[d:\tempfolder with a long name\] [e\test.jpg]
Press any key to continue . . .


@echo off
setlocal
set lfn="d:\tempfolder with a long name\a test.jpg"


for %%a in (%lfn%) do set sfn=%%~sfa & set ln=%%~nxa
for %%a in (%sfn%) do set spn=%%~dpa
for %%a in (%spn%%ln%) do set sn=%%~snxa
echo [%spn%] [%sn%]

pause

OOTANI TAKASHI

unread,
Mar 23, 2004, 8:45:32 AM3/23/04
to
foxidrive <foxi...@Shotmail.com> writes:
>>>> See this post for an explanation of the %~spi bug and a workaround
>>>> without using COMMAND.COM.
>>>>
>>>> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3d41032e.28814222%40192.168.0.2
>>>>
>>>> Garry
>>>
>>>Sorry Garry, I can't manage to get the correct short path\filename using
>>>the techniques you mention from that URL.
>>
>> OK try this. The idea is to break up the LFN into its path/file
>> components and convert each separately. It's a bit more complex when
>> you have to also get the filename as a SFN.

Dividing the LFN into only 2parts (path/file) is not enough.
We must convert each element of the LFN separately.

> Unfortunately this kind of file upsets it.

...


> set lfn="d:\tempfolder with a long name\a test.jpg"

...

This works well. (Fortunately I have D: drive.)
Output is:
["d:\tempfolder with a long name\a test.jpg"]
[d:\TEMPFO~1\ATEST~1.JPG]

------>8------>8------>8------>8------>8------>8------>8------
@echo off
setlocal
rem set lfn="c:\temp\tempfolder with a long name\0=3=biz.jpg"


set lfn="d:\tempfolder with a long name\a test.jpg"

call :sfnsub %lfn:\=\" "%
echo [%lfn%]
echo [%sfn%]
goto :eof

:sfnsub
set sfn=
:loop
if "%~1"=="" goto :eof
for %%A in ("%sfn%%~1") do set sfn=%%~sA
shift /1
goto loop
------>8------>8------>8------>8------>8------>8------>8------

But it's too heavy to get only a short name.
May MS fix this bug in the next SP?

--
tksotn in JP

Garry Deane

unread,
Mar 23, 2004, 10:45:53 PM3/23/04
to
On Tue, 23 Mar 2004 10:18:48 GMT, foxidrive <foxi...@Shotmail.com>
wrote:

>Unfortunately this kind of file upsets it.
>
>===[screen copy]===
>[d:\tempfolder with a long name\] [e\test.jpg]
>Press any key to continue . . .
>
>
>@echo off
>setlocal
>set lfn="d:\tempfolder with a long name\a test.jpg"
>for %%a in (%lfn%) do set sfn=%%~sfa & set ln=%%~nxa
>for %%a in (%sfn%) do set spn=%%~dpa
>for %%a in (%spn%%ln%) do set sn=%%~snxa
>echo [%spn%] [%sn%]
>pause

Yes, you're right. Although I could get the above path to work, I was
unable to get a correct result if the path was sufficiently devious.

So I went back to your original suggestion of using Command.com. By
quarantining Command.com within a FOR process, you can get the correct
result without breaking %%~fa.

@echo off
setlocal
set lfn="\tempfolder with a long name\sp\l p\a test.txt"
md %lfn%\.. 2> nul
echo test > %lfn%
pushd %lfn%\..
for /f %%a in ('command /c cd') do set spn=%%a
popd
for %%a in (%lfn%) do set ln=%%~nxa
for %%a in ("%spn%\%ln%") do set sn=%%~snxa
echo [%spn%] [%sn%]
for %%a in (%lfn%\..\*) do echo [%%~fa]
rd /s/q %lfn%\..

Garry

foxidrive

unread,
Mar 24, 2004, 5:13:22 AM3/24/04
to
On Tue, 23 Mar 2004 22:45:32 +0900, OOTANI TAKASHI wrote:

> This works well. (Fortunately I have D: drive.)
> Output is:
> ["d:\tempfolder with a long name\a test.jpg"]
> [d:\TEMPFO~1\ATEST~1.JPG]
>
> ------>8------>8------>8------>8------>8------>8------>8------
> @echo off
> setlocal
> rem set lfn="c:\temp\tempfolder with a long name\0=3=biz.jpg"
> set lfn="d:\tempfolder with a long name\a test.jpg"
> call :sfnsub %lfn:\=\" "%
> echo [%lfn%]
> echo [%sfn%]
> goto :eof
>
>:sfnsub
> set sfn=
>:loop
> if "%~1"=="" goto :eof
> for %%A in ("%sfn%%~1") do set sfn=%%~sA
> shift /1
> goto loop
> ------>8------>8------>8------>8------>8------>8------>8------

I adapted this - but I still have a glitch to iron out.

I just wanted to say thanks, and to Garry as well. My interest in this is
not just academic... I use Qbasic in many tools and need to open long
filenames for reading. As Qbasic predates long filenames I need the short
path\filename - so there is a practical application for me.


> But it's too heavy to get only a short name.
> May MS fix this bug in the next SP?

That'd be nice, but seeing how the bug has been around so long it seems
unlikely.

Todd Vargo

unread,
Mar 24, 2004, 5:46:46 PM3/24/04
to

"foxidrive" <foxi...@Shotmail.com> wrote in message
news:1krca19o8emq2.7...@40tude.net...

Have you tried extracting the sfn from DIR/X? It would require walking the
path back to the root. Unfortunately, FOR/F does not work in Win95cmd as far
as parsing file contents goes, so I can not provide you a working example.

I have to go now, but I could offer some air code tomorrow. ?

foxidrive

unread,
Mar 24, 2004, 10:50:42 PM3/24/04
to
On Wed, 24 Mar 2004 17:46:46 -0500, Todd Vargo wrote:

> "foxidrive" <foxi...@Shotmail.com> wrote in message
> news:1krca19o8emq2.7...@40tude.net...

>> I just wanted to say thanks, and to Garry as well. My interest in this is
>> not just academic... I use Qbasic in many tools and need to open long
>> filenames for reading. As Qbasic predates long filenames I need the short
>> path\filename - so there is a practical application for me.

> Have you tried extracting the sfn from DIR/X? It would require walking the
> path back to the root. Unfortunately, FOR/F does not work in Win95cmd as far
> as parsing file contents goes, so I can not provide you a working example.
> I have to go now, but I could offer some air code tomorrow. ?

Thank for the suggestion - I've looked at that but in their wisdom MS have
implemented a routine for dir /x that only prints the short filename in the
screen position if it is a long filename. That would entail even more code
to get all the filenames.

But I can happily report that I have two routines which appear to handle
all filenames. I'll post them below.

This is based on OOTANI TAKASHI's code, and takes 60 seconds on 2,800
files, but is quite convoluted.

@echo off
type nul>temp.tmp
echo generating file list...
for /f "delims=" %%a in ('dir *.gif /b /on') do (
echo %%~fa>>temp.tmp
call :sfnsub "%%~fa"
)
for /f "delims=" %%a in ('dir *.jpg /b /on') do (
echo %%~fa>>temp.tmp
call :sfnsub "%%~fa"
)
goto :EOF
:sfnsub
set var=%*
set var=%var:\=\" "%
set sfn=
call :loop %var%
goto :EOF
:loop


for %%A in ("%sfn%%~1") do set sfn=%%~sA
shift

if not "%~1"=="" goto :loop
set "sfn2=%sfn:&=^&%"
echo/%sfn2%>>temp.tmp
if not exist "%sfn%" echo %sfn% doesn't exist
goto :EOF

This is based on using command.com within pushd/popd commands and takes 70
seconds on the same 2,800 files.

@echo off
type nul>temp.tmp
echo generating file list...
for /f "delims=" %%a in ('dir *.gif /b /on') do (
echo %%~fa>>temp.tmp
call :sfnloop "%%~fa"
)
for /f "delims=" %%a in ('dir *.jpg /b /on') do (
echo %%~fa>>temp.tmp
call :sfnloop "%%~fa"
)
goto :EOF
:sfnloop
pushd .
command /c rem
for %%b in ("%~1") do echo %%~sa>>temp.tmp
popd
goto :EOF

To Garry, your last solution worked fine and is between the two solutions
above in complexity.

Todd Vargo

unread,
Mar 25, 2004, 12:26:08 AM3/25/04
to

"foxidrive" wrote:
> Thank for the suggestion - I've looked at that but in their wisdom MS have
> implemented a routine for dir /x that only prints the short filename in
the
> screen position if it is a long filename. That would entail even more
code
> to get all the filenames.

Yes, but is that not what we enjoy doing? ;-)

BTW, did you know there *are* LFN to SFN routines for qbasic?

foxidrive

unread,
Mar 25, 2004, 1:14:16 AM3/25/04
to
On Thu, 25 Mar 2004 00:26:08 -0500, Todd Vargo wrote:

> "foxidrive" wrote:
>> Thank for the suggestion - I've looked at that but in their wisdom MS have
>> implemented a routine for dir /x that only prints the short filename in
> the
>> screen position if it is a long filename. That would entail even more
> code
>> to get all the filenames.
>
> Yes, but is that not what we enjoy doing? ;-)

Natürlich :)



> BTW, did you know there *are* LFN to SFN routines for qbasic?

I hadn't ever thought to look for any - but did find some, and related
tools for dos. Thanks for the tip.

foxidrive

unread,
Mar 26, 2004, 12:58:57 PM3/26/04
to
On Thu, 25 Mar 2004 03:50:42 GMT, foxidrive wrote:

> But I can happily report that I have two routines which appear to handle
> all filenames. I'll post them below.

Well, almost all filenames... after some more use I found an exception, but
I don't blame the routines for the failure coz it is probably due more to
the mishandling of accented characters.

I had a filename containing an "ã" character (not sure how it'll display,
it's an "a" with ~ above it) and both routines returned a short path with a
long filename (with the accented "ã" replaced with a normal hex 61 "a"
character).

Just thought I'd update the thread...

OOTANI TAKASHI

unread,
Mar 26, 2004, 1:49:38 PM3/26/04
to

Yes, I made mistake, I had not tested special chars only space and = when last posted.
Always special characters cause troubles.
I think these lines are a little better than above.
set "sfn=%sfn:&=^&%"
set "sfn=%sfn:^^=^%"
echo/%sfn%>>temp.tmp


if not exist %sfn% echo %sfn% doesn't exist
goto :EOF

But this still does not work well for filenames containing %,
because it isn't passed to subroutine.

> This is based on using command.com within pushd/popd commands and takes 70
> seconds on the same 2,800 files.

.....


> :sfnloop
> pushd .
> command /c rem
> for %%b in ("%~1") do echo %%~sa>>temp.tmp
> popd
> goto :EOF

This subroutine does not work for general case.
The effect of "command /c rem" is only convert current directory name
from LFN to SFN. So it must CD to target directory.
:sfnloop
pushd .
cd /d "%~dp1"
command /c rem
for %%b in ("%~nx1") do echo %%~sb>>temp.tmp
popd
goto :EOF
But this does not work well for filenames containing ^ not only % .


BTW, I don't like the welcome message of command.com appear on the screen
when it run on cmd.exe at the first time. Are there any TIPs suppress it?
--
tksotn

foxidrive

unread,
Mar 26, 2004, 10:36:40 PM3/26/04
to
On Sat, 27 Mar 2004 03:49:38 +0900, OOTANI TAKASHI wrote:

> Always special characters cause troubles.

> But this still does not work well for filenames containing %,
> because it isn't passed to subroutine.

> The effect of "command /c rem" is only convert current directory name

> from LFN to SFN. So it must CD to target directory.
> :sfnloop
> pushd .
> cd /d "%~dp1"
> command /c rem
> for %%b in ("%~nx1") do echo %%~sb>>temp.tmp
> popd
> goto :EOF
> But this does not work well for filenames containing ^ not only % .

It works well enough for me, but it'd be nice if MS ploughed some R&D into
fixing and enhancing cmd.exe

> BTW, I don't like the welcome message of command.com appear on the screen
> when it run on cmd.exe at the first time. Are there any TIPs suppress it?

This doesn't occur on my PC...

OOTANI TAKASHI

unread,
Mar 27, 2004, 5:00:16 AM3/27/04
to
foxidrive <foxi...@Shotmail.com> writes:
> On Sat, 27 Mar 2004 03:49:38 +0900, OOTANI TAKASHI wrote:
>> But this does not work well for filenames containing ^ not only % .
>
> It works well enough for me, but it'd be nice if MS ploughed some R&D into
> fixing and enhancing cmd.exe

Indeed I don't have no file its name contains ^ in my PC but for testing.
But there are some files those name contain % in my PC.
It may come from why % is used for showing spacial characters as hexadecimal.
e.g. http://somewhere/%7Emy/A%3DB.html
Files under "Temporary Internet Files" may not be important.
I have a few % files in Basilisk(Mac emulator on WIN) directories.
Anyway they are minority. I also give up here.

>> BTW, I don't like the welcome message of command.com appear on the screen
>> when it run on cmd.exe at the first time. Are there any TIPs suppress it?
>
> This doesn't occur on my PC...

I see. I've found.
It must be effect of IME (that enables us to input Japanese charactors).
I'll check it, thank you.
--
tksotn

0 new messages