Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

8.3 file path to full path...

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
Madshi
Asked:
Madshi
  • 6
  • 6
  • 3
1 Solution
 
MirkwoodCommented:
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
 
BlackManCommented:
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
 
MirkwoodCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MadshiAuthor Commented:
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
 
MirkwoodCommented:
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
 
BlackManCommented:
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
 
MadshiAuthor Commented:
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
 
MirkwoodCommented:
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
 
MirkwoodCommented:
Whooh, 3 languages in one comment.
0
 
MadshiAuthor Commented:
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
 
MirkwoodCommented:
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
 
MadshiAuthor Commented:
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
 
MadshiAuthor Commented:
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
 
BlackManCommented:
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
 
MadshiAuthor Commented:
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now