DosTips.com

A Forum all about DOS Batch
It is currently 30 Aug 2016 12:46

All times are UTC-06:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: 11 Apr 2012 14:00 
Offline

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


Top
   
PostPosted: 11 Apr 2012 14:05 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2234
Location: Germany
What about
Code:
%~dps0

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


Regards
aGerman


Top
   
PostPosted: 11 Apr 2012 14:07 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5914
Just be aware that the ~s short name function has a bug and sometimes returns the wrong info.


Top
   
PostPosted: 11 Apr 2012 14:07 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
aGerman wrote:
Code:
for %%i in ("%cd%") do echo %%~s0


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


Top
   
PostPosted: 11 Apr 2012 14:18 
Offline

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


Top
   
PostPosted: 11 Apr 2012 14:26 
Offline

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


Top
   
PostPosted: 11 Apr 2012 14:42 
Offline
Expert

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


Top
   
PostPosted: 11 Apr 2012 15:06 
Offline

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 8 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 9 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® Forum Software © phpBB Limited