Solved

Short file names for DOS based utilities

Posted on 1998-10-22
14
141 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 93
Communication Between RC4 Delphi <-> PHP 3 99
QRReport  TQrmemo vertical stretching 1 42
Delphi inherited method 6 60
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now