パスからルートパスを取り出す          <TOP>


PathStripToRoot パスからルートパスを取り出す
 

 

'================================================================
'= パスからルートパスを取り出す
'=    (PathStripToRoot.bas)
'================================================================
#include "Windows.bi"

' パスからルートパスを取り出す
Declare Function Api_PathStripToRoot& Lib "shlwapi" Alias "PathStripToRootA" (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:\THE DIR\MYFILE\"
End Sub

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

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

    Ret = Api_PathStripToRoot(sSave)
    
    Text1.SetWindowText TrimNull(sSave)
End Sub

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