Last active
August 24, 2024 14:34
-
-
Save Richienb/51021a1c16995a07478dfa20a6db725c to your computer and use it in GitHub Desktop.
Download A File In Visual Basic Script (vbs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub HTTPDownload( myURL, myPath ) | |
Dim i, objFile, objFSO, objHTTP, strFile, strMsg | |
Const ForReading = 1, ForWriting = 2, ForAppending = 8 | |
Set objFSO = CreateObject( "Scripting.FileSystemObject" ) | |
If objFSO.FolderExists( myPath ) Then | |
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) ) | |
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then | |
strFile = myPath | |
Else | |
WScript.Echo "ERROR: Target folder not found." | |
Exit Sub | |
End If | |
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True ) | |
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" ) | |
objHTTP.Open "GET", myURL, False | |
objHTTP.Send | |
For i = 1 To LenB( objHTTP.ResponseBody ) | |
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) ) | |
Next | |
objFile.Close( ) | |
End Sub | |
HTTPDownload "DOWNLOADURL", "DOWNLOADDESTINATION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got expected ')' error when replacing myURL with download link
