ファイルやフォルダの検索 <TOP>
ファイルやフォルダを検索します。
SearchPath ファイルやフォルダを検索
'================================================================ '= ファイルやフォルダの検索 '= (SearchPath.bas) '================================================================ #include "Windows.bi" ' ファイルやフォルダを検索する Declare Function Api_SearchPath& Lib "Kernel32" Alias "SearchPathA" (ByVal lpPath$, ByVal lpFileName$, ByVal lpExtension$, ByVal nBufferLength&, ByVal lpBuffer$, ByVal lpFilePart$) #define MAX_PATH 260 #define vbNullString ByVal 0 '値0の文字列。値0を持つ文字列。空文字列ではない Var Shared Text(2) As Object Var Shared Edit(3) As Object Var Shared Button1 As Object For i = 0 To 3 If i < 3 Then Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1))) : Text(i).SetFontSize 14 Edit(i).Attach GetDlgItem("Edit" & Trim$(Str$(i + 1))) : Edit(i).SetFontSize 14 Next Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var Path As String Var FileName As String Var Extension As String Var FullPath As String Var Ret As Long Path = Edit(0).GetWindowText FileName = Edit(1).GetWindowText Extension = Edit(2).GetWindowText FullPath = Space$(MAX_PATH) If Path = "" And Extension = "" Then Ret = Api_SearchPath(vbNullString, FileName, vbNullString, MAX_PATH, FullPath, vbNullString) Else Ret = Api_SearchPath(Path, FileName, Extension, MAX_PATH, FullPath, vbNullString) End If If Ret = 0 Then Edit(3).SetWindowText "ファイルは見つかりません!" Else Edit(3).SetWindowText FullPath End If End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End