ディレクトリ取得(3題)          <TOP>


ディレクトリ(3)を取得します。

GetCurrentDirectory 自プロセスのカレントディレクトリを取得

GetSystemDirectory Windowsのシステムディレクトリのパスを取得

GetWindowsDirectory Windowsディレクトリのパス名を取得
 

 

 

'================================================================
'= ディレクトリ取得3題
'================================================================
#include "Windows.bi"

' 自プロセスのカレントディレクトリを取得
Declare Function Api_GetCurrentDirectory& Lib "kernel32" Alias "GetCurrentDirectoryA" (ByVal nBufferLength&, ByVal lpBuffer$)

' Windows のシステムディレクトリのパスを取得。システムディレクトリには、Windows ライブラリ、ドライバなどのファイルが置かれている
Declare Function Api_GetSystemDirectory& Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer$, ByVal nSize&)

' Windowsディレクトリのパス名を取得
Declare Function Api_GetWindowsDirectory& Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer$, ByVal nSize&)

Var Shared Text1 As Object
Var Shared Text2 As Object
Text1.Attach GetDlgItem("Text1")
Text2.Attach GetDlgItem("Text2")

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

    Directory = String$(255, 0)
    Ret = Api_GetCurrentDirectory(255, Directory)
    Text1.SetWindowText "カレントディレクトリ"
    Text2.SetWindowText Directory
End Sub

'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var Directory As String
    Var Ret As Long

    Directory = String$(255, 0)
    Ret = Api_GetSystemDirectory(Directory, 255)
    Directory = Left$(Directory, Ret)
    Text1.SetWindowText "システムディレクトリ"
    Text2.SetWindowText Directory
End Sub

'================================================================
'=
'================================================================
Declare Sub Button3_on edecl ()
Sub Button3_on()
    Var Path As String
    Var Directory As String
    Var Ret As Long

    Directory = String$(255, Chr$(0))
    Ret = Api_GetWindowsDirectory(Directory, Len(Directory))
    Directory = Left$(Directory, Ret)
    Text1.SetWindowText "Windowsディレクトリ"
    Text2.SetWindowText Directory
End Sub

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