Evaluating short path/file names

Ulvis

Member
Joined
Sep 29, 2003
Messages
6
Location
Norway
How does one evaluate short path names into long path names as in the following example:
Short form: "D:\fl72\FACTOR~1\APPLIC~1\STARTE~1" ,
should evaluate to: "D:\fl72\FactoryLink\Applications\Starter App"

I have looked at the System.IO.Path class : Path.GetFullPath(..) , but from VisualStudio Help [ms-help://MS.VSCC/MS.MSDNVS/ cpref/html/frlrfsystemiopathclassgetfullpathtopic.htm] it reads: "If you pass in a short file name, it is not expanded to a long file name."

I have also looked at the Directory and DirectoryInfo classes, but to no avail. There are however clues of how to do this using the WinAPI along the lines of the BrowseForFolder demo from(http://www.developingskills.com/ds.php?article=dsbrowseforfolder&page=1).

Does anyone know how to do this the .NET way ?

/Erik.
 
Once you have a short path I doubt that you can get the long from it, why are you getting the short path to begin with?
 
The short form path comes from an environment variable.
The path stored in the variable is put there by the installation procedure of the software I am trying to interface, (FactoryLink) and is out of my control.

I guess I can do fine with the short form path for my project, but still I want to know how to move between short and long path names.

Erik
 
you can get your long path quite easily using the GetLongPathName Api ( modified for .NET purposes ) , heres a quick example i knocked you up ...
Code:
    Private Declare Function GetLongPathName Lib "kernel32.dll" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As System.Text.StringBuilder, ByVal cchBuffer As Integer) As Integer

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim fullpath As New System.Text.StringBuilder(256)
        Dim shortpath As String = "C:\PROGRA~1\GAMEHO~1\Mahjong" /// your short path goes here.

        GetLongPathName(shortpath, fullpath, fullpath.Capacity)

        MessageBox.Show(fullpath.ToString)
    End Sub
 
Excellent, thank you !

Only thing is that the string returned contains the path create date; "D:\fl72\FactoryLink\Applications\Starter App 1-12-2004 09-09-57"
Are there options to strip this date/time from the path or do I have to do this manually ?

Erik
 
A correction to my last reply !

Somehow I had 2 directories named "Starter App" in my tree, and one of them was indeed named "Starter App 1-12-2004 09-09-57", hence the output decsibed in my last post.

Human error....
 
Back
Top