Is it possible to read files like .css and .js from a URL? For instance, I have a file, which is located at http://main/shared/css/main.css
, and want to read this file and store its content in another file at c:\main.txt
. I know how to read files in local drives but not sure how to do it for a URL. Any help is much appreciated.
Asked
Active
Viewed 6,723 times
2

Ansgar Wiechers
- 193,178
- 25
- 254
- 328

user505210
- 1,362
- 11
- 28
- 50
-
2Yes it is possible (as soon as the PC you run the VBScript on has an internet access of course!), and I think you'll find you answer in [this SO question](http://stackoverflow.com/questions/204759/http-get-in-vbs) – Laurent S. Jun 19 '13 at 14:02
-
1possible duplicate of [Download a file with VBS](http://stackoverflow.com/questions/2973136/download-a-file-with-vbs) – Helen Jun 19 '13 at 15:17
3 Answers
4
You can use an XMLHttpRequest
for this:
url = "http://main/shared/css/main.css"
Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "GET", url, False
req.send
If req.Status = 200 Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.OpenTextFile("C:\main.txt", 2).Write req.responseText
End If

Ansgar Wiechers
- 193,178
- 25
- 254
- 328
0
Yes as long as you know the file names in question you should be able to do a simple XMLHttpRequest

Dan K
- 409
- 3
- 12
-2
url = "http://main/shared/css/main.css"
Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "GET", url, False
req.send
If req.Status = 200 Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.OpenTextFile("C:\main.txt", 8, true, 0).Write req.responseText
End If
A slight amend to the OpenTextFile line so the text file is created locally if it does not exist.

John A Cove
- 1
- 1