开发者

Script to download file by name according to date on a Windows?

开发者 https://www.devze.com 2023-01-27 17:28 出处:网络
I need to daily run a script that will download a file from a fixed location (http:/开发者_如何学编程/www.meteoman.it/ilmeteo/audio/) and save it on my computer.

I need to daily run a script that will download a file from a fixed location (http:/开发者_如何学编程/www.meteoman.it/ilmeteo/audio/) and save it on my computer. The format of filename is yyyy-mm-dd.mp3 and everyday a new file in added. The script must recognize the date and save the appropriate file whit the date of today in the folder "today" and the file whit the date of tomorrow in the folder "tomorrow". thank you !!!

the script if for automate the forecast on my web-radio the file of forecast are freeware sorry for my English! cheers from Italy


The calls to Right are to pad the month and day with a leading zero if needed (adds a zero to any month/day and then extract only the last 2 digits).

dt = Date
yearStr = Year(dt)
monthStr = Right("0" & Month(dt), 2)
dayStr = Right("0" & Day(dt), 2)
fileName = yearStr & "-" & monthStr & "-" & dayStr & ".mp3"

To get tomorrow's date, just change the first line to:

dt = DateAdd("d", 1, Date)


here the script ! tnx all!

    dt = Date
yearStr = Year(dt)
monthStr = Right("0" & Month(dt), 2)
dayStr = Right("0" & Day(dt), 2)
fileName = yearStr & "-" & monthStr & "-" & dayStr & ".mp3"



 ' Set your settings
    strFileURL = "http://www.meteoman.it/ilmeteo/audio/" & filename
    strHDLocation = "c:\today\today.mp3"
' Fetch the file
    Set Ws = WScript.CreateObject("WScript.Shell")
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    objXMLHTTP.open "GET", strFileURL, false
    objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0    'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End If
' Set objXMLHTTP = Nothing 
' Ws.Run strHDLocation
' Set WS = Nothing
0

精彩评论

暂无评论...
验证码 换一张
取 消