"."や".."などの文字を含まないパス名に変換          <TOP>


PathCanonicalize "."や".."などの文字を含むパス名を、これらの文字を含まないパス名に変換
 

 

'================================================================
'= "."や".."などの文字を含まないパス名に変換
'=    (PathCanonicalize.bas)
'================================================================
#include "Windows.bi"

' "."や".."などの文字を含むパス名を、これらの文字を含まないパス名に変換
Declare Function Api_PathCanonicalize& Lib "shlwapi" Alias "PathCanonicalizeA" (ByVal pszBuf$, ByVal pszPath$)

Var Shared Edit1 As Object
Var Shared Text1 As Object
Var Shared Button1 As Object

Edit1.Attach GetDlgItem("Edit1") : Edit1.SetFontSize 14
Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'= Chr$(0)を取り除く
'================================================================
Declare Function TrimNull (item As String) As String
Function TrimNull(item As String) As String
    Var ePos As Integer

    ePos = Instr(item, Chr$(0))
    If ePos Then
        TrimNull = Left$(item, ePos - 1)
    Else
        TrimNull = item
    End If
End Function

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Edit1.SetWindowText "c:\dir1\.\dir2\..\dir3"
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var sSave As String
    Var Buff As String
    Var Ret As Long

    Buff = String$(100, 0)
    sSave = Edit1.GetWindowText

    Ret = Api_PathCanonicalize(Buff, sSave)
    
    Text1.SetWindowText TrimNull(Buff)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End