我正在自动化一个项目,每个月我都需要访问网站并从那里复制文件。 我能够复制文件,问题是它们的名字如下所示,所以我无法知道那个月要复制哪个文件。
filename2015011023549.zip
filename2015021922876.zip
有没有办法从网站获取文件列表?
答案 0 :(得分:1)
您将包含文件列表的页面(请参阅内嵌注释)下载到本地文件,然后解析该文件以寻找可能的文件名候选者:
Option Compare Database
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) _
As Long
Public Function DownloadFile( _
ByVal strURL As String, _
ByVal strLocalFilename As String) _
As Long
' Download file or page with public access from the web.
' 2004-12-17. Cactus Data ApS, CPH.
' Usage, download a file:
' lngRet = DownloadFile("http://www.databaseadvisors.com/Graphics/conf2002/2002ConferencePicsbySmolin/images/dba02smolin27.jpg", "c:\happybassett.jpg")
'
' Usage, download a page:
' lngRet = DownloadFile("http://www.databaseadvisors.com/conf2002/conf200202.asp", "c:\dbaconference.htm")
' Returns 0 if success, error code if not.
' Error codes:
' -2146697210 "file not found".
' -2146697211 "domain not found".
' Limitation.
' Does not check if local file was created successfully.
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, strURL & vbNullChar, strLocalFilename & vbNullChar, 0, 0)
DownloadFile = lngRetVal
End Function