Solved

Short file names for DOS based utilities

Posted on 1998-10-22
14
146 Views
Last Modified: 2010-04-06
When I retrieve a long file name, how can I retrieve it so that DOS based utilities (third party, retrieved by an achaeologist, but ideal in this instance) can use the file name?

For example MyFileAbcdefPlusMoreStuff has to be passed as MyFile~1 (or whatever is appropriate).
0
Comment
Question by:dejohn99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1344046
You can do just like this... If Length(FileName) > 5 then FileName := Copy(FileName, 1, 5) + '~1';

Or here is an original solution to this one....Haven't tested it but it should work.....

function ShortPath( Path : string) : string;
var
  Len : Integer;
  Short : String;
  pShort : PChar;
begin
  Result := '';
  Len := Length(Path);
  pShort := StrAlloc(Len);
  GetShortPathName(PChar(Path), pShort, Len);
  Short := pShort;
  StrDispose(pShort);
  Result := Short;
end;

Cheers,
Viktor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344047
Hi dejohn99,

and viktor was first... jsut when I was making a demo...
well, here you got a slight other approach.

procedure TForm1.Button1Click(Sender: TObject);

Function GetShortFileName(Const FileName : String) : String;
var
  aTmp: array[0..255] of char;
begin
  if GetShortPathName(PChar(FileName),aTmp,Sizeof(aTmp)-1)=0 then
     Result:= FileName
  else
     Result:=StrPas(aTmp);
end;

begin
 if OpenDialog1.Execute then begin
  showmessage(getshortfilename(opendialog1.Filename));
 end;
end;

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344048
this one was tested and even cuts the too long paths.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1344049
This does the same thing....

function ShortPath( Path : string) : string;
var
  pPath : array[0..MAX_PATH] of char;
begin
  GetShortPathName(PChar(Path), pPath, MAX_PATH - 1);
  Result := StrPas(pPath);
end;

Cheers,
Viktor Ivanov
0
 

Author Comment

by:dejohn99
ID: 1344050
Guess what guys, I have tried your codes BUT ...

The path returned by the function is always empty!  Am I missing something???

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344051
Have you just pasted my code into a form-unit? And tried it out? It works perfectly here.... What version of Delphi are you using?
Zif.
0
 

Author Comment

by:dejohn99
ID: 1344052
Sorry vik - Zifnab's code helped me more.  Thanks for the assists though.
0
 

Author Comment

by:dejohn99
ID: 1344053
Zifnab - You truly are a wizard greater than Gandalf - even if he did have a Balrog hanging from his skivvies.  You can even do Dorothy today if you want!

Please resubmit as an answer for your points.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1344054
Dejohn99,

I know, I know I'm a greater wizard then Gandalf, it's because I'm Gandalf myself! Oh, nope I'm not, I even don't know a Gandalf... I'm 007... yep that's me... (sorry, couldn't resist... because you refering to Gandalf.... great also a AD&D player, or something else?)

Just wizarding :

Comment
       From: ZifNab
                                                                                   Date: Thursday, October 22 1998 - 03:57PM PDT

       Hi dejohn99,

       and viktor was first... jsut when I was making a demo...
       well, here you got a slight other approach.

       procedure TForm1.Button1Click(Sender: TObject);

       Function GetShortFileName(Const FileName : String) : String;
       var
         aTmp: array[0..255] of char;
       begin
         if GetShortPathName(PChar(FileName),aTmp,Sizeof(aTmp)-1)=0 then
            Result:= FileName
         else
            Result:=StrPas(aTmp);
       end;

       begin
        if OpenDialog1.Execute then begin
         showmessage(getshortfilename(opendialog1.Filename));
        end;
       end;

Regards, Zif.
0
 

Author Comment

by:dejohn99
ID: 1344055
Well if you're 007 today, then watch out for Moneypenney, or was that Q ... hmmm

I'm not a D&D player - I prefer GURPS.

I think we must read some of the same books for fun though.

TTYL   <grin>
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344056
John, what is GURPS?
0
 

Author Comment

by:dejohn99
ID: 1344057
Generic
Universal
Role
Playing
System

It's a lot simpler, better organized and flexible than D&D - more of a simulations rule set.  Any scenario from prehistoric through science fiction can be played, including sometimes bizzarre combinations like magic versus high-tech versus psionics.  You could conceivably drop a D&D Magic User into a star trek episode, or Captain Kirk into Brahm Stoker's Dracula.  (What would Dr. McCoy make of Vlad Dracula?  "He's undead Jim" ??)

But the purpose of any game is pure fun, so go for it!!!   :-)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344058
Hi John, somewhere an url about GURPS?
0
 

Author Comment

by:dejohn99
ID: 1344059
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 102
CheckListBox usage 3 96
Delphi problems to abort a printjob 9 46
Problem working with dynamic array - help 2 47
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question