Solved

8.3 file path to full path...

Posted on 1999-01-28
15
422 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

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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