这个问题在这里已有答案:
我希望能够下载每周发布的.MP3播客,我有一个下载文件的工作脚本,问题是文件名每周更改一次(日期在文件名中)
新闻2018-12-09.mp3,
新闻2018-12-16.mp3,
新闻2018-12-23.mp3 .
这是我的代码:
# Start IE and navigate to your download file/location
$ie = New-Object -Com internetExplorer.Application
$ie.Navigate("<address>2018-12-09.mp3")
# Wait for Download Dialog box to pop up
Sleep 5
while ($ie.Busy) {Sleep 1}
# Hit "S" on the keyboard to hit the "Save" button on the download box
$obj = New-Object -Com WScript.Shell
$obj.AppActivate('Internet Explorer')
$obj.SendKeys('s')
# Hit "Enter" to save the file
$obj.SendKeys('{Enter}')
# Closes IE Downloads window
$obj.SendKeys('{TAB}')
$obj.SendKeys('{TAB}')
$obj.SendKeys('{TAB}')
$obj.SendKeys('{Enter}')
是否有特定的Regex序列可以检查和文件名,下载当前的序列,并且可能在保存文件时,将其保存为 news-current.mp3
?
1 回答
如果你知道文件的格式总是
news-
当前日期.mp3
那么构造它就不难了..像$fileName = 'news-{0}.mp3' -f (Get-Date -Format 'yyyy-MM-dd')
之类的东西会这样做 .至于下载文件的方式,我认为有更好的方法来实现这一点,而不是使用Internet Explorer Com对象 .