trying to pull down all files created on a specifc date using ftpFindFirstFile

andyuk
andyuk used Ask the Experts™
on
hFind = FtpFindFirstFile(hConnection, "*.csv", pData, 0, 0)

How could I use this to find all the files created on a specific date?

Andrew
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
   hOpen = InternetOpen("ftp Generic", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
   
    hConnect = InternetConnect(hOpen, Url, 0, FtpId & "@" & ProxyId & "@" & Url, FtpPwd & "@" & ProxyPwd, 1, INTERNET_FLAG_PASSIVE, 0)
   
    If hConnect = 0 Then
        MsgBox "You were unable to connect to the Server : " & Url, vbCritical, "Internet Connection"
        Exit Sub
    End If
   
    'Enumerate the Directory putting values into the File* Array
    pData.cFileName = String(MAX_PATH, 0)
    hFind = FtpFindFirstFile(hConnect, "*.*", pData, 0, 0)
   
    If hFind = 0 Then
        If nLastError = ERROR_NO_MORE_FILES Then
            MsgBox "This directory is empty!", vbInformation, " Site is Empty"
            Exit Sub
        End If
    End If
   
    FileName(x) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    FileSize(x) = pData.nFileSizeLow
    Holder = FileTimeToSystemTime(pData.ftLastWriteTime, strDate)
    FileDate(x) = strDate.wMonth & "-" & strDate.wDay & "-" & strDate.wYear
   
    x = 1
   
    Do While x < 10
        pData.cFileName = String(MAX_PATH, 0)
        bRet = InternetFindNextFile(hFind, pData)
        If bRet = False Then
            nLastError = Err.LastDllError
            If nLastError = ERROR_NO_MORE_FILES Then
                Exit Do
            Else
                TotalFiles = x
                Exit Sub
            End If
        Else
            FileName(x) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
            FileSize(x) = pData.nFileSizeLow
            Holder = FileTimeToSystemTime(pData.ftLastWriteTime, strDate)
            FileDate(x) = strDate.wMonth & "-" & strDate.wDay & "-" & strDate.wYear
            x = x + 1
        End If
        DoEvents
    Loop


This is how I do it to get all the files on the server you would just need to add some validation based on the file date.  This bit of code also assumes the following:
Dim strDate As SYSTEMTIME
Dim pData As WIN32_FIND_DATA
Public Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
End Type

Public Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
End Type


Hopefully this will get you started.  Let me know if you need more.

G

Author

Commented:
Been looking at this code for ages and still trying to work out whats happening.  I tried putting the code into vb but i think i need to dim alot of the varaibles

Commented:
andy,
Yes sorry, this is a snipet from a much much larger project.  If you tell me which variables are giving you a problem I can try to get you more of the declares.
G

Author

Commented:
Many thanks.  Worked around your code and figure out the general idea.

Thanks again

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial