A
A
Artyom2019-01-27 08:46:39
VBScript
Artyom, 2019-01-27 08:46:39

How to write a file to a temporary folder in vbs?

Hello, there is a code that downloads files and then saves them to the specified paths.
The code works great, but I have a problem.
I need to save files to a temporary folder
, for me it looks like this C:\Users\7272~1\AppData\Local\Temp
Can I use a script to call the name of the temporary folder in the system, and then substitute the resulting value using a variable in that code where are the links to the files?
because I looked that on my Windows 10 the user temp folder is located at C:\Users\USER_NAME\AppData\Local\Temp\ and on windows xp it already looks like
this C:\Documents And Settings\USER_NAME\Local Settings\Temp\
to simplify this process a little so that the save path is substituted automatically))

set d = CreateObject("Scripting.Dictionary")
d.Add "0", "прямая ссылка на файл 1|D:\file1.txt"
d.Add "1", "прямая ссылка на файл 2|E:\Temp\trash.txt"
Set x = CreateObject("MSXML2.XMLHTTP")
For Each i In d     
 x.open "GET", Split(d.Item(i), "|")(0), false
 x.send()
 If x.Status = 200 Then
  With CreateObject("ADODB.Stream")
   .Open
   .Type = 1
   .Write x.ResponseBody
   .Position = 0
   .SaveToFile Split(d.Item(i), "|")(1), 2
   .Close
  End With
 End If
Next

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-01-27
@fishmen

Set oShell = CreateObject( "WScript.Shell" )
temp=oShell.ExpandEnvironmentStrings("%TEMP%")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question