Solved

Short file names for DOS based utilities

Posted on 1998-10-22
14
144 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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