A
A
Alexander Zharchenko2017-03-22 12:16:01
JavaScript
Alexander Zharchenko, 2017-03-22 12:16:01

How to add destination folder when downloading in JavaScript?

I'm not into programming, but recently the task arose - by launching a file (the same .wsf) to ensure that the desired object is downloaded via a direct link. Since this is not possible through the standard Windows console, I found a working javascript code on the Internet, but it lacks a destination folder, i.e. folder where the file will be downloaded. By default, the file is placed on the desktop, but how can I specify a specific folder?

<job>
 <script language="JScript">
 
 httpGet("http://forum.ixbt.com/bbtitle-ixbt.gif");
 
 function httpGet(url)
 {
  var fname=url.replace(/.+\//,"");
  with(new ActiveXObject("WinHttp.WinHttpRequest.5.1"))
  {
   open("GET",url);
   send();
   if(status==200)
    with(new ActiveXObject("ADODB.Stream"))
    {
     type=1;
     open();
     write(responseBody);
     saveToFile(fname,2);
    }
  }
 }
 
 </script>
</job>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2017-03-22
@exxxcitation1

var fname=url.replace(/.+\//,"");
fname = 'd:\\path\\to\\file\\' + fname;

It would be better to put wget for Windows
Then it will be easy
wget -P d:\path http://site.com/file.rar

A
Anton Anton, 2017-03-22
@Fragster

install curl, wget or the whole cygwin and enjoy. Also powershell can do it for sure. well, in this case, specify the full file name as the saveToFile argument.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question