Понадобилось получать данные о банках по БИК. Честно думал, уже есть что-то готовое, но гугл не помог.
Проблема возникает при распаковке архива от Банка России. Как костыль поставил просто задержку, но хотелось бы, чтобы код останавливался, а потом понимал, что распаковка завершена и возобновлялся.
Приложил пример, xml не прикрепляется, так что в архиве, если с Банка России качать, то там ок 700 кБ
Код
Sub DownloadBikFile(myPath As String, fileName As String)
Dim HttpObj As Object, StreamObj As Object, FileObj As Object
Set HttpObj = CreateObject("Microsoft.XMLHTTP")
HttpObj.Open "GET", "http://cbr.ru/s/newbik", False
HttpObj.send
If HttpObj.Status = 200 Then
Set StreamObj = CreateObject("ADODB.Stream")
StreamObj.Open
StreamObj.Type = 1
StreamObj.Write HttpObj.responseBody
StreamObj.SaveToFile myPath & "\temp.zip", 2
StreamObj.Close
CreateObject("WScript.Shell").Exec ("powershell -command Expand-Archive -LiteralPath '" & myPath & "\temp.zip" & "' -DestinationPath '" & myPath & "'")
'===================================================
Application.Wait Now + #12:00:05 AM#
'===================================================
Set FileObj = CreateObject("Scripting.FileSystemObject")
FileObj.getfile(myPath & "\temp.zip").Delete
FileObj.getfile(myPath & "\" & fileName).Delete
For Each i In FileObj.getfolder(myPath).Files
If Right(i.Name, 3) = "xml" Then
i.Name = fileName
Exit For
End If
Next
End If
End Sub
Sub DownloadBikFile(myPath As String, fileName As String)
Dim HttpObj As Object, StreamObj As Object, FileObj As Object, deCompObj As Object
Set HttpObj = CreateObject("Microsoft.XMLHTTP")
HttpObj.Open "GET", "http://cbr.ru/s/newbik", False
HttpObj.send
If HttpObj.Status = 200 Then
Set StreamObj = CreateObject("ADODB.Stream")
StreamObj.Open
StreamObj.Type = 1
StreamObj.Write HttpObj.responseBody
StreamObj.SaveToFile myPath & "\temp.zip", 2
StreamObj.Close
Set deCompObj = CreateObject("WScript.Shell").Exec("powershell -command Expand-Archive -LiteralPath '" & myPath & "\temp.zip" & "' -DestinationPath '" & myPath & "'")
Do While deCompObj.Status = 0
Loop
Set FileObj = CreateObject("Scripting.FileSystemObject")
FileObj.getfile(myPath & "\temp.zip").Delete
If FileObj.FileExists(myPath & "\" & fileName) Then FileObj.getfile((myPath & "\" & fileName)).Delete
For Each i In FileObj.getfolder(myPath).Files
If Right(i.Name, 3) = "xml" Then
i.Name = fileName
Exit For
End If
Next
End If
End Sub