0

我在 Windows 7 中使用 vbscript 编写 wscript。脚本需要从打开的 ftp 服务器中获取文件,因此我必须使用 MSXML2.XMLHTTP 对象

我正在抓取的文件被缓存在 C:\Users\user\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5 的子文件夹中

缓存的文件没有“过期”值,尝试使用 setRequestHeader 方法设置值似乎没有任何效果。

如果其他人需要此解决方案,我将自行回​​答

4

1 回答 1

0

此代码片段显示如何从 MSXML2.XMLHTTP 使用的文件夹中删除缓存文件,使用下载文件的概念将具有扩展名“.csv”

<job>
<script language="vbscript">

' use XMLHTTP to grab content from a URL

CMEURL = "ftp://ftp.cmegroup.com/pub/settle/nymex_future.csv"

' the downloaded files are being stored in a subfolder of this folder
filedownloadcachelocation =  "C:\Users\user\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5"

' delete the file before requesting a download

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fileresults 

Dim Directory
Set Directory = fso.GetFolder(filedownloadcachelocation)
Dim subfolders
Set subfolders = Directory.SubFolders
For Each Folder In subfolders
    For Each FileName In Folder.Files
        ' only react if filename extension is csv
        If InStr(FileName , ".csv") Then
            fileresults = fileresults & FileName.Path & vbLf 

            ' delete the file
            If fso.FileExists(FileName.Path) Then
                'WScript.Echo "deleting file " & FileName.Path
                fso.DeleteFile FileName.Path
            End If


        End If ' csv ext
    Next ' each file in folder
Next ' each folder in Content.IE5

WScript.Echo "files found that were deleted = " & VbLf & fileresults

' now continue with downloading the file using XMLHTTP
于 2018-04-20T15:36:36.377 回答