Resolve Relative Path [Resolved]
Is there a way to resolve a relative path reference in VB 6? For example, if I have reference to the file "..\SomeFile.dat" (with the ..\ meaning that the file is located one level above the current directory), is there an API function or some other method to expand the ".."?
Re: Resolve Relative Path
Take a look at the Sample By Randy Birch . There are many other samples.
Re: Resolve Relative Path
Quote:
Originally Posted by RhinoBull
That only returns true or false if you pass a relative path to it. The following code will "unfold" a relative path. However it doesn't actually checks to see if the path exists, so in your case you should pass CurDir & "..\SomeFile.dat" for it to create a correct path.
VB Code:
Private Declare Function PathCanonicalize _
Lib "shlwapi.dll" _
Alias "PathCanonicalizeA" ( _
ByVal pszBuf As String, _
ByVal pszPath As String) As Long
Public Function UnfoldRelativePath(ByVal sPath As String) As String
Dim sBuff As String
sBuff = Space$(261)
If PathCanonicalize(sBuff, sPath) Then
UnfoldRelativePath = Left$(sBuff, InStr(sBuff, vbNullChar) - 1)
Else
UnfoldRelativePath = sPath
End If
End Function
Re: Resolve Relative Path
Thanks, Joacim!
It took a little playing around with, but this is what finally worked for me (the file I want to reference resides one level above where the app is running:
MsgBox UnfoldRelativePath(App.Path & "\..") & "\Somefile.dat"
Re: Resolve Relative Path [Resolved]
Why wouldn't this work:
MsgBox UnfoldRelativePath(App.Path & "\..\Somefile.dat")
Re: Resolve Relative Path [Resolved]
Actually, that does work. (As I mentioned, I was experimenting with various combinations until I saw the light; your example simplifies mine.)