Solved

Short file names for DOS based utilities

Posted on 1998-10-22
14
149 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
Industry Leaders: 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

Technology Partners: 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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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