Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

8.3 file path to full path...

Posted on 1999-01-28
15
Medium Priority
?
424 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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