View unanswered posts | View active topics It is currently 02 Sep 2014 07:59



Post new topic Reply to topic  [ 8 posts ] 
Convert current directory to DOS 8.3-friendly shortname 
Author Message

Joined: 31 Mar 2012 21:31
Posts: 160
Post Convert current directory to DOS 8.3-friendly shortname
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.


11 Apr 2012 14:00
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1753
Location: Germany
Post Re: Convert current directory to DOS 8.3-friendly shortname
What about
Code:
%~dps0

or
Code:
for %%i in ("%cd%") do echo %%~si


Regards
aGerman


11 Apr 2012 14:05
Profile
Online

Joined: 10 Feb 2012 02:20
Posts: 4119
Post 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.


11 Apr 2012 14:07
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: Convert current directory to DOS 8.3-friendly shortname
aGerman wrote:
Code:
for %%i in ("%cd%") do echo %%~s0


Shouldn't it be "%%~si"?
Edit: Nevermind. You edited it already.


11 Apr 2012 14:07
Profile WWW

Joined: 31 Mar 2012 21:31
Posts: 160
Post 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!


11 Apr 2012 14:18
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post 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.


11 Apr 2012 14:26
Profile WWW
Expert

Joined: 22 Jan 2010 18:01
Posts: 1753
Location: Germany
Post 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


11 Apr 2012 14:42
Profile

Joined: 31 Mar 2012 21:31
Posts: 160
Post 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%

Code:
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.

Quote:
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


11 Apr 2012 15:06
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.