Ulvis Posted February 11, 2004 Posted February 11, 2004 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. Quote
Moderators Robby Posted February 11, 2004 Moderators Posted February 11, 2004 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? Quote Visit...Bassic Software
Ulvis Posted February 11, 2004 Author Posted February 11, 2004 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 Quote
Leaders dynamic_sysop Posted February 11, 2004 Leaders Posted February 11, 2004 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 Quote
Ulvis Posted February 12, 2004 Author Posted February 12, 2004 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 Quote
Ulvis Posted February 12, 2004 Author Posted February 12, 2004 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.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.