Solved

8.3 file path to full path...

Posted on 1999-01-28
15
420 Views
Last Modified: 2010-04-04
Can please somebody give me a complete and working function that converts a path like "c:\docume~1\blabla~1\blabla~1.txt" to "c:\documents\blablabla\blablabla.txt"?

Something like

function DosPathToFullPath (dosPath: string; var fullPath: string) : boolean;

Thank you very much!

Regards, Madshi.
0
Comment
Question by:Madshi
[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
  • 3
15 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1363651
This is the VB declare of the API
Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long


0
 
LVL 7

Accepted Solution

by:
BlackMan earned 50 total points
ID: 1363652
It's easier than you think :-)
I had the same problem when I made an application that supported files being dropped from the Explorer on to it, and I solved it this way:

  FindFirst(AShortName, faAnyFile, SearchRec);
  ALongFileName := SearchRec.Name;
  FindClose(SearchRec);

I guess I don't have to tell you that you need to declare SearchRec first ;-)
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1363653
Oh Madshi, it's you. Congratulations with your top100 spot.
Here is a delphi example. Let me know.


// First, lets convert a long file name to a short one

procedure TForm1.Button9Click(Sender: TObject);
 Var
  ShortPath, LongPath : Array[0..MAX_PATH] Of Char;
  PathLen : Integer;
  strLongPath : String;
begin
 strLongPath := FileListBox1.FileName;
  GetShortPathName(pChar(strLongPath), ShortPath, SizeOf(ShortPath));
 Label3.Caption := ShortPath;
end;


// Now lets convert it back to a long filename

procedure TForm1.Button10Click(Sender: TObject);
 Var
  Buffer: Array[0..MAX_PATH] of Char;
  FName : String;
  Length: DWORD;
  Add: PChar;
begin
// We get the short filename from the previous procedure
  FName := Label3.Caption;
  Length := GetFullPathName(PChar(FName), MAX_PATH + 1, Buffer, Add);
  Label4.Caption := StrPas(Buffer);
end;



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 20

Author Comment

by:Madshi
ID: 1363654
Wow, thank you both for the quick response!

Mirkwood, I tried to the GetFullPathName API before asking this question. But it seems that it doesn't work somehow.
I tried something like "Label3.Caption:='c:\progra~1';" (in my german windows the folder is called "c:\programme"). But GetFullPathName just gives 'c:\progra~1' back...   :-(
What am I doing wrong?
Hmmm. And what do you mean with the "top100 spot"?

BlackMan, your idea works, but I have to go through all the folders. I can't convert the whole path with one call. And calling FindFile several times seems to be not so fast in my eyes, or am I wrong?

I would prefer a single call to "GetFullPathName". But in the moment it doesn't work somehow...   :-(

So Mirkwood, if you tell me, what I'm doing wrong, you'll get the points. Otherwise they'll go to BlackMan.

Thanx again...

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1363655
Hi Madshi,
The top100 can be found at http://www.experts-exchange.com/info/top100.htm
You are a newcomer in the top100 this week on place 97.

I'll look into the GetFullPathName
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1363656
Hmm, I sliped my eyes that it was the full path, you wanted to expand. I do think though, that if there is a function to expand it, it will just do the FindFirst calls for you, it has to go to the directory to find the full name..
0
 
LVL 20

Author Comment

by:Madshi
ID: 1363657
Hi Mirkwood, thanx for the top 100 link. Didn't know this before. I see you're straightly heading for the top 10...  :-)

BlackMan, maybe you're right. I'll wait and see what Mirkwood finds out with GetFullPathName...

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1363658
Someone needs to be shot in the API team.

GetFullName does something completly wild.
Take a look at
c := GetFullPathName(".", cMaxPath, sFullname, pbase);

In win98 and winNT5 the correct function does exist
Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long


This piece of assembly does the trick.
mov ax, 7160h
mov cl, 2                  ; Get Long Path Name
mov ch, SubstExpand        ; UNC or Drive letters (1/0)
mov si, seg SourcePath     ; Short path
mov ds, si
mov si, offset SourcePath
mov di, seg DestPath       ; Long path
mov es, di
mov di, offset DestPath
int 21h
jc  error

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1363659
Whooh, 3 languages in one comment.
0
 
LVL 20

Author Comment

by:Madshi
ID: 1363660
Uaaaa! What shall I do now?
That means there's no API for win95?
I should better use FindFile (as BlackMan suggested) than using these assembler calls, or what do you think? I mean, can I use this assembler in Delphi? "seg" and "offset" is 16 bit code, isn't it? Would that assembler code work for win95/98/NT4/NT5?

You're right. Someone has to be shot...

Thank you... Madshi.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1363661
Sure you can use assembly in delphi. It works in both win95/winNT and higher, but try to be sure. Good luck.

Here is a sample. BTW: Do you have ICQ?

http://www.lars.com.pl/ftp/DELPHI/BORLAND_/TI2854.HTM
0
 
LVL 20

Author Comment

by:Madshi
ID: 1363662
Yes, I know that I can use assembler in Delphi, I've programmed several functions in assembler. But your code looks like 16 bit code (with "seg" and "offset"). My 32 bit Delphi4 can't compile it. And the functions from "www.lars.com.pl/..." work only in 16 bit windows (respectively Delphi 1), too...

My ICQ number is 22710005...  :-)
0
 
LVL 20

Author Comment

by:Madshi
ID: 1363663
Hmm. I could not get Mirkwood's assembler part to work, so the points are yours, BlackMan.

Thanks to both of you for your help...   :-)

Regards, Madshi.
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1363664
Just found this MS article, seems like they do it "my way" to :-)

http://support.microsoft.com/support/kb/articles/q154/8/22.asp?FR=0
0
 
LVL 20

Author Comment

by:Madshi
ID: 1363665
Hi BlackMan, yes, I found this article, too...  :-)
But in win98/NT5 there is a "real" API to do it, so I hoped for a better solution for win95/NT4, too. However, "your" way works quite fine. And perhaps/probably the "real" API does internally the same as we do.
Thanx again...  :-)
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

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