wininet.dll API を使用して ftp サイトで一致するファイルを検索しようとしましたが、何らかの理由で機能しません。これが私が使用してきた方法です。
Private Sub DoStuff()
Dim hConnection As Long, hOpen As Long, sOrgPath As String, lRes As Long
Dim scUserAgent$
scUserAgent$ = "vb wininet"
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hConnection = InternetConnect(hOpen, mServer$, INTERNET_DEFAULT_FTP_PORT, mUserid$, mPassword$, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
''//set the current directory to 'root/testdir/testdir2'
FtpSetCurrentDirectory hConnection, "testdir/testdir2"
ReDim matchingFiles$(1)
Call SearchForFiles(hConnection, ".txt", matchingFiles$)
''//Close the connections
InternetCloseHandle hConnection
InternetCloseHandle hOpen
End Sub
ここに SearchForFiles 関数があります
Public Sub SearchForFiles(hConnection As Long, fileExtension$, matchingFiles$())
Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
Dim i%
ReDim matchingFiles$(1)
i% = 1
''//create a buffer
pData.cFileName = String(MAX_PATH, 0)
''//find the first file
hFind = FtpFindFirstFile(hConnection, "*." + fileExtension$, pData, 0, 0)
''//if there is no file, then exit sub
If hFind = 0 Then Exit Sub
''//show the filename
matchingFiles$(i%) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
Do
i% = i% + 1
''//create a buffer
pData.cFileName = String(MAX_PATH, 0)
''//find the next file
lRet = InternetFindNextFile(hFind, pData)
''//if there is no next file, exit do
If lRet = 0 Then Exit Do
''//show the filename
ReDim Preserve matchingFiles$(UBound(matchingFiles) + 1)
matchingFiles$(i%) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
Loop
''//close the search handle
InternetCloseHandle hFind
End Sub
私が得続けるのは「。」だけです。SearchForFiles 関数から返されるファイルの場合は ".." です。私は何か間違ったことをしていますか?
ありがとう!