Solved

8.3 file path to full path...

Posted on 1999-01-28
15
412 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

22 Experts available now in Live!

Get 1:1 Help Now