|
-
Mar 6th, 2005, 07:40 PM
#1
Thread Starter
PowerPoster
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 ".."?
Last edited by BruceG; Mar 6th, 2005 at 09:31 PM.
"It's cold gin time again ..."
Check out my website here.
-
Mar 6th, 2005, 07:44 PM
#2
Re: Resolve Relative Path
Take a look at the Sample By Randy Birch . There are many other samples.
-
Mar 6th, 2005, 08:17 PM
#3
Re: Resolve Relative Path
 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
-
Mar 6th, 2005, 09:31 PM
#4
Thread Starter
PowerPoster
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"
"It's cold gin time again ..."
Check out my website here.
-
Mar 7th, 2005, 04:27 AM
#5
Re: Resolve Relative Path [Resolved]
Why wouldn't this work:
MsgBox UnfoldRelativePath(App.Path & "\..\Somefile.dat")
-
Mar 7th, 2005, 07:16 AM
#6
Thread Starter
PowerPoster
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.)
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|