我创建了一个Powershell脚本来下载MP4s,当我指定一个文件夹时它工作正常。但我想从所有文件夹下载文件。
当我指定101GOPRO
时,这是有效的$iwr = Invoke-WebRequest http://10.5.5.9:8080/videos/DCIM/101GOPRO/
$links = $iwr.Links | select href | where {$_.href -like "*mp4"} | select -expand href
foreach ($link in $links) {
$url = "http://10.5.5.9:8080/videos/DCIM/101GOPRO/" + $link
$target = "C:\"
start-bitstransfer -source $url -destination $target -TransferType Download
}
如何仅通过指定http://10.5.5.9:8080/videos/DCIM/
来获取所有文件夹中的.mp4s谢谢!
答案 0 :(得分:1)
没有更多信息,这只是一个猜测,但你可以根据你的情况修改它
$site = 'http://10.5.5.9:8080/videos/DCIM/'
$base = iwr $site
$subs = $base.links.href
$subs
# only remove this when you have filtered your results
return
foreach ($sub in $subs) {
$subsite = join-path $site $sub
write-host $subsite
$iwr = iwr $subsite
$links = $iwr.Links.href | where {$_ -like "*mp4"}
foreach ($link in $links) {
$url = join-path $subsite $link
write-host $url
start-bitstransfer -source $url -destination 'c:\' -TransferType Download
# this is an alternative to start-bitstransfer
#iwr $url -outfile "c:\$(split-path $url -leaf)"
}
}