【问题标题】:How to solve file download path error in VBScript ?如何解决VBScript中的文件下载路径错误?
【发布时间】:2017-08-12 18:36:44
【问题描述】:

我正在运行以下 VBScript 程序,download.vbs

dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "http://websitelink/textfile.txt", False
xHttp.Send

with bStrm
.type = 1 '//binary
.open
.write xHttp.responseBody
.savetofile "c:\dump.txt", 2 '//overwrite
end with

在这个程序中,它将从给定的网址下载文本文件并将其保存到给定路径的本地磁盘。

但问题是,当我将下载路径更改为本地磁盘d:时,它运行良好

当我使用本地磁盘c:作为下载路径时显示以下错误。

VBScript 错误信息,

Script:     C:\test\download.vbs
Line:       10
Char:       5
Error:      Write to file failed.
Code:       800A0BBC
Source:     ADODB.Stream

请帮忙。我会非常感激的。

【问题讨论】:

标签: vbscript


【解决方案1】:

如果文件不存在 - 你想在 safetofile 上使用 1。你可以添加一些代码

Const AdTypeBinary = 1, AdTypeText = 2
Const FsoRead = 1, FsoWrite = 2, FsoAppend = 8
Const BstrmCreate = 1, BstrmOvrWrt = 2
dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "http://websitelink/textfile.txt", False
xHttp.Send
mysavefile = "D:\dump.txt" 'Set your save-file here 



with bStrm
    .type = AdTypeBinary ' YOU MAY WANT TO CHANGE FILE TYPE FOR TEXT/BINARY
    .open
    .write xHttp.responseBody

    if ( FSO.FileExists( mysavefile ) ) then
        .savetofile mysavefile, BstrmCreate
    else
        .savetofile mysavefile, BstrmOvrWrt
    end if
end with

【讨论】:

    猜你喜欢
    • 2020-02-16
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    • 1970-01-01
    相关资源
    最近更新 更多