| 项目搜索 |
| |
|
代码片段库:
查看代码片段
浏览
| 提交新的代码片段
| 创建代码包
Creates a relative path from one file or folder to another.
|
类型:
Function |
类别:
File Management
|
许可证:
GNU General Public License |
语言:
Visual Basic
|
描述:
Creates a relative path from one file or folder to another.
|
该代码片段的版本系列:
片段ID |
下载版本 |
提交时间 |
提交人 |
删除 |
4835 | 1.0 | 2003-11-30 04:58 | cbd001 | |
点击"下载版本"来下载该代码片段.
最新版本的代码片段: 1.0
Private Declare Function PathRelativePathTo Lib "shlwapi.dll" Alias "PathRelativePathToA" (ByVal pszPath As String, ByVal pszFrom As String, ByVal dwAttrFrom As Long, ByVal pszTo As String, ByVal dwAttrTo As Long) As Long
Private Const MAX_PATH As Long = 260
Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
'-----------------------------------------------------------
' Creates a relative path from one file or folder to another.
'
' made by Alexander Triantafyllou [email protected]
'
' usage relative_path=get_relative_path_to(root_path,file_path)
' get_relative_path_to("d:\a\b\c\d","d:\a\b\index.html") will return
' "..\..\index.html"
' use FILE_ATTRIBUTE_DIRECTORY if the path is a directory
' or FILE_ATTRIBUTE_NORMAL if the path is a file
'----------------------------------------------------------
Public Function get_relative_path_to(ByVal parent_path As String, ByVal child_path As String) As String
Dim out_str As String
Dim par_str As String
Dim child_str As String
out_str = String(MAX_PATH, 0)
par_str = parent_path + String(100, 0)
child_str = child_path + String(100, 0)
PathRelativePathTo out_str, par_str, FILE_ATTRIBUTE_DIRECTORY, child_str, FILE_ATTRIBUTE_NORMAL
out_str = StripTerminator(out_str)
'MsgBox out_str
get_relative_path_to = out_str
End Function
'Remove all trailing Chr$(0)'s
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
如果您修改了一个代码片段并且觉得很应该让别人共享,您可以把这作为这个代码片段的最新版本提交上来. |
|