Tuesday, June 19, 2007

SNTT - Resolving a relative path

I recently needed to resolve a relative path, such as C:\Windows\..\autoexec.bat. Dir$ will tell you whether the path is valid, but what if you want to display the resolved path without the relative references? The secret (at least on Windows and in LotusScript) is the mostly undocumented shlwapi.dll library. Here's a few lines of code that will do it for you:
(Declarations)
Declare Function PathCombine Lib "shlwapi.dll" Alias "PathCombineA" _
(Byval szDest As String, Byval lpszDir As String, Byval lpszFile As String) As Long

Sub Click(Source As Button)
Dim sFullPath As String
Dim sResolvedPath As String

sFullPath = "C:\Windows\System32\drivers\..\..\..\autoexec.bat"
Msgbox sFullPath
sResolvedPath = Space$(255)
Call PathCombine(sResolvedPath, sFullPath, "")
sResolvedPath = Left$(sResolvedPath, Instr(1, sResolvedPath, Chr$(0)) - 1)

Msgbox sResolvedPath
End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

No comments:

Post a Comment