Link to home
Start Free TrialLog in
Avatar of Selva m
Selva m

asked on

VB script to get count(number) of files present in the URL based on the Last modified date

I am able to access the URL which holds many more xml file and .csv files i want to get the count based on the last modified date. Could you please guide on this. I am very beginner to VB script
Avatar of Bill Prew
Bill Prew

What's the URL of the page you want to get this info from?

~bp
Avatar of Selva m

ASKER

http://reports.ieso.ca/public/DispUnconsHOEP/?C=M%3bO=D

I want to get count of .csv/*.xml files based on the last modified date
Sub Q_28994281()
    Dim oXMLHTTP
    Dim strHTML
    Dim oRE
    Dim oMatches
    Dim oM
    Dim oDic
    Dim vItem
    
    Set oDic = CreateObject("scripting.dictionary")
    
    Set oRE = CreateObject("vbscript.regexp")
    oRE.Global = True
    oRE.Pattern = ">([^<]+\.(?:csv|xml))</a>\s+(\d\S+)"

    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    oXMLHTTP.Open "GET", "http://reports.ieso.ca/public/DispUnconsHOEP/?C=M%3bO=D", False
    oXMLHTTP.Send
    
    Do Until oXMLHTTP.ReadyState = 4
        DoEvents
    Loop
    
    If oXMLHTTP.Status = 200 Then
        strHTML = oXMLHTTP.responsetext
        'parse the result
        If oRE.test(strHTML) Then
            Set oMatches = oRE.Execute(strHTML)
            For Each oM In oMatches
                With oM
                    If oDic.exists(.submatches(1)) Then
                        oDic(.submatches(1)) = oDic(.submatches(1)) + 1
                    Else
                        oDic(.submatches(1)) = 1
                    End If
                End With
            Next
        End If
        For Each vItem In oDic
            'persist or process the dates and counts
            'Debug.Print vItem, oDic(vItem)
        Next
    Else
        MsgBox "response does not match regex pattern"
    End If
    
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Selva m

ASKER

Great. That works fine thanks a lot. But i want to click on Last modified date and get the count, Please guide on this.
You want to click where, on the original web page?  In the output file of my script?  Please be more specific on your desired need.

~bp
Avatar of Selva m

ASKER

When i click on  Last modified column the data's are arranged in date wise. In that i wanna get a count of files that is present  in yesterday. Count of Files(.Csv/xml) that were created on yesterday only.
wp_ss_20170123_0001.png
I don't see any way to do that, since you are clicking on the actual web page, not anything that is under control of the script.

~bp
Avatar of Selva m

ASKER

Ok thank you so much.
Avatar of Selva m

ASKER

Is it possible to read the data from last( From end of page)
Avatar of Selva m

ASKER

Great