I need a way to convert the current directory to DOS 8.3 short name.
Currently I call the current directory with %CD%. However, I need the short name equivalent of that.
Convert current directory to DOS 8.3-friendly shortname
Moderator: DosItHelp
Re: Convert current directory to DOS 8.3-friendly shortname
Just be aware that the ~s short name function has a bug and sometimes returns the wrong info.
Re: Convert current directory to DOS 8.3-friendly shortname
aGerman wrote:Code: Select all
for %%i in ("%cd%") do echo %%~s0
Shouldn't it be "%%~si"?
Edit: Nevermind. You edited it already.
Re: Convert current directory to DOS 8.3-friendly shortname
Does anyone know under what circumstances this wont work? Is this the best know way to reliably get the current directory as a short name?
Thanks a million!
Thanks a million!
Re: Convert current directory to DOS 8.3-friendly shortname
MKANET wrote:Does anyone know under what circumstances this wont work? Is this the best know way to reliably get the current directory as a short name?
Thanks a million!
Well I've managed to write a script to echo a short path to a .tmp file and start it with notepad. You can then copy the text and, right after you close notepad, the file is deleted.
Re: Convert current directory to DOS 8.3-friendly shortname
I remember that thread:
http://stackoverflow.com/questions/8354 ... short-name
also
viewtopic.php?f=3&t=2583
Seems to be a bug on XP.
Regards
aGerman
http://stackoverflow.com/questions/8354 ... short-name
also
viewtopic.php?f=3&t=2583
Seems to be a bug on XP.
Regards
aGerman
Re: Convert current directory to DOS 8.3-friendly shortname
Currently, I just insert this line of code into my batch files that depend on %CD%
I saw a piece of code to make it a bit safer (in the above links). However, not sure how I would incorporate it into my code; or, if it would help any.
Code: Select all
for %%i in ("%cd%") do set CD=%%~si
I saw a piece of code to make it a bit safer (in the above links). However, not sure how I would incorporate it into my code; or, if it would help any.
Maybe some code like this would make it more robust:
convert using var=%%~sA
:loop
if not exist "%var%\" remove last character and goto :loop
hopefully %var% here will be the short filename