Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 [http://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.

Posted

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

  • Leaders
Posted

you can get your long path quite easily using the GetLongPathName Api ( modified for .NET purposes ) , here's a quick example i knocked you up ...

   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

Posted

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

Posted

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....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...