Hello All,
Iam facing some problem in listing out the directory files in SD card, if the files in SD Card are more than 3000, iam getting the no. of files as ZERO.
Please see the below code snippet and let me know how can i get the exact no. & details of files if the CARD has more than 3000 files:
Private Function DoFilesList(sFilter As String) As Boolean
On Error GoTo errHandler
Dim dt As WIN32_FIND_DATA
Dim hFile As Long, sFile
Dim x As Long
Dim sFilename As String
Dim ftLastWriteTime As FILETIME
Dim nFileSize As Long
AddToLogFile ("Inside DoFileList")
For x = cFileCardList.count To 1 Step -1
cFileCardList.Remove x
Next
DoEvents
hFile = FtpFindFirstFile(hConnect, sFilter, dt, INTERNET_FLAG_RELOAD, INTERNET_FLAG_NO_CACHE_WRITE)
sFile = 1
Do Until sFile = 0
If ((dt.dwFileAttributes And Not vbDirectory)) Then
sFilename = Left(dt.cFileName, InStr(1, dt.cFileName, String(1, 0), vbBinaryCompare) - ONE)
' 2.17.01 changes begin
ftLastWriteTime = dt.ftLastWriteTime
' Size of the file needs to be calculated
nFileSize = dt.nFileSizeHigh * (MAXDWORD + 1) + dt.nFileSizeLow
AddtoCardList sFilename, nFileSize, FileTimeToDate(ftLastWriteTime)
' 2.17.01 changes end
End If
sFile = InternetFindNextFile(hFile, dt)
Loop
InternetCloseHandle (hFile)
InternetCloseHandle (sFile)
DoFilesList = True
AddToLogFile ("Existing DoFilesList")
Exit Function
errHandler:
DoFilesList = False
Resume Next
End Function
Private Sub AddtoCardList(ByVal sFilename As String, ByVal FileSize As Long, ByVal FileModifiedTime As Date)
Dim newItem As cFileItem
Set newItem = New cFileItem
With newItem
.Filename = sFilename
.FileSize = FileSize
.LastWriteTime = FileModifiedTime
End With
cFileCardList.Add newItem
Set newItem = Nothing
End Sub
the below part is from FTP APIs wich we are using:
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal pub_lngInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Long
Public Const INTERNET_OPTION_CONNECT_TIMEOUT = 2
Public Const INTERNET_OPTION_RECEIVE_TIMEOUT = 6
Public Const INTERNET_OPTION_SEND_TIMEOUT = 5
This is the function which we are using to connect through FTP socket:
Private Function FtpConnect(ConnectionName As String, Port As Integer, User As String, Password As String, Optional ProxyName As String, Optional ProxyBypass As String) As Boolean
On Error GoTo errHandler
Dim thrh As String
Dim k As Integer
Dim pingchk As Boolean
Dim URL As String
Dim buffer As Long
Dim iRetVal As Integer
k = ZERO
pingchk = TryPingToAll
If pingchk = False Then
AddToLogFile ("Pinging IP-address failed")
FtpConnect = False
Exit Function
Else
AddToLogFile ("Pinging IP-address success")
End If
Do
DoEvents
If FTP_IP_SET = FTP_IP_USBDEVICE Then
hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
URL = FTP_IP_USBDEVICE
thrh = "USB Device"
CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
hConnect = InternetConnect(hSession, FTP_IP_USBDEVICE, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
End If
If FTP_IP_SET = FTP_IP_ETH0 Then
hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
URL = FTP_IP_ETH0
thrh = "Ethernet"
CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
hConnect = InternetConnect(hSession, FTP_IP_ETH0, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
End If
If FTP_IP_SET = FTP_IP_WIFI Then
hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
URL = FTP_IP_WIFI
thrh = "WifI Device"
CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
hConnect = InternetConnect(hSession, FTP_IP_WIFI, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
End If
If FTP_IP_SET = FTP_IP_WIFI_AP Then
hSession = InternetOpen(ConnectionName, INTERNET_OPEN_TYPE_DIRECT, ProxyName, ProxyBypass, INTERNET_FLAG_NO_CACHE_WRITE)
URL = FTP_IP_WIFI_AP
thrh = "WifI Device"
CallbackResult = InternetSetStatusCallback(hSession, AddressOf InternetStatusCallback)
hConnect = InternetConnect(hSession, FTP_IP_WIFI_AP, Port, User, Password, INTERNET_SERVICE_FTP, FTP_TRANSFER_TYPE_BINARY, DW_CONTEXT&)
End If
buffer = 120000
iRetVal = InternetSetOption(hConnect, INTERNET_OPTION_RECEIVE_TIMEOUT, buffer, 4)
buffer = 120000
iRetVal = InternetSetOption(hConnect, INTERNET_OPTION_SEND_TIMEOUT, buffer, 4)
buffer = 120000
iRetVal = InternetSetOption(hConnect, INTERNET_OPTION_CONNECT_TIMEOUT, buffer, 4)
If hSession <> ZERO And hConnect <> ZERO Then
Exit Do
End If
InternetCloseHandle (hSession)
InternetCloseHandle (hConnect)
hSession = ZERO: hConnect = ZERO
k = k + ONE
Loop Until (hSession <> ZERO And hConnect <> ZERO) Or k = ONE
If hSession <> ZERO And hConnect <> ZERO Then
DoEvents
FtpConnect = True
Exit Function
Else
FtpConnect = False
End If
Exit Function
errHandler:
InternetCloseHandle (hSession)
InternetCloseHandle (hConnect)
FtpConnect = False
End Function
Please suggest how can i list out directory if file siize is more than 3GB
Thanks.
Dinesh