VBScript Download flag SVG files from a website

Visual Basic Script

Here is a VBScript script to download flag SVG files from a website and save them in a directory

Set xml = CreateObject("MSXML2.ServerXMLHTTP.6.0")
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")

urlTemplate = "https://commons.wikimedia.org/wiki/Special:FilePath/Flag_of_{country}.svg"
outputFolder = shell.CurrentDirectory & "\flags"

countries = Array("Afghanistan", "Albania", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Aruba", _
    "Bahamas", "Bangladesh", "Barbados", "Belarus", "Belize", "Benin", "Bermuda", "Bhutan", _
    "Bosnia and Herzegovina", "Botswana", "British Virgin Islands", "Brunei", "Burundi", "Cambodia", _
    "Cameroon", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", _
    "Comoros", "Congo", "Cook Islands", "Côte d'Ivoire", "Democratic Republic of the Congo", "Dominica", _
    "El Salvador", "Equatorial Guinea", "Eswatini", "Fiji", "Gabon", "Gambia", "Georgia", "Ghana", _
    "Grenada", "Guam", "South Sudan", "United States Virgin Islands", "Uruguay", "Uzbekistan")

If Not fso.FolderExists(outputFolder) Then
    fso.CreateFolder(outputFolder)
End If

For Each country In countries
    countryUrl = Replace(urlTemplate, "{country}", Replace(country, " ", "_"))
    xml.Open "GET", countryUrl, False
    xml.Send
    
    If xml.Status = 200 Then
        Set stream = CreateObject("ADODB.Stream")
        stream.Type = 1 ' adTypeBinary
        stream.Open
        stream.Write xml.responseBody
        stream.SaveToFile outputFolder & "\" & country & ".svg", 2 ' adSaveCreateOverWrite
        stream.Close
        WScript.Echo "Downloaded: " & country
    Else
        WScript.Echo "Failed to download: " & country
    End If
Next

 

 

 

Shopping Cart