Êàê ñãåíåðèðîâàòü îòíîñèòåëüíûé ïóòüPrivate Declare Function PathRelativePathToW _ Lib “shlwapi.dll” (ByVal pszPath As Long, _ ByVal pszFrom As Long, ByVal dwAttrFrom As _ Long, ByVal pszTo As Long, ByVal dwAttrTo _ As Long) As Boolean Private Function GetRelativePath( _ sRelativePath As String, ByVal sPathFrom _ As String, ByVal sPathTo As String) As _ Boolean Dim bResult As Boolean Const MAX_PATH As Long = 260 sRelativePath = Space(MAX_PATH) ' Set “dwAttr...” to vbDirectory for ' directories, 0 for files bResult = PathRelativePathToW(StrPtr _ (sRelativePath), StrPtr(sPathFrom), _ vbDirectory, StrPtr(sPathTo), 0) If bResult Then sRelativePath = Left(sRelativePath, _ InStr(sRelativePath, vbNullChar) - 1) Else sRelativePath = ““ End If GetRelativePath = bResult End Function Private Sub Command1_Click() Dim sRelative As String ' txtFromPath should contain the directory ' path to go from, txtToPath should contain ' the file path to go to. ' txtRelativePath will contain the result If GetRelativePath(sRelative, _ txtFromPath.Text, txtToPath.Text) Then txtRelativePath.Text = sRelative Else txtRelativePath.Text = “Error” End If End Sub
|