我使用IE浏览器创建了一个简单的图像循环。我遇到了一个代码问题。
如果删除循环中的下一个图像,我会收到错误cannot find the file
。
代码:
$duration = 5 # duration between slides
$repeat = 99999999 # how many times do you want to repeat the images
for ($i=0; $i -lt $repeat ; $i++) {
$image = (Get-ChildItem C:\testing\image\*.jpg).name
ForEach ($imageitem in $image) {
$ie = New-Object -COMObject InternetExplorer.Application -Property`
@{Navigate2="C:\testing\image\$imageitem";
Visible = $true
}
$ie
sleep -Seconds $duration
$ie.Quit()
}
}
答案 0 :(得分:0)
这是我修改代码的方式:
$duration= 5 # duration between slides
$repeat=99999999 # how many times do you want to repeat the images
for ( $i=0; $i -lt $repeat ; $i++){
$image=(Get-ChildItem C:\testing\image\*.jpg).FullName
ForEach ($imageitem in $image){
if(test-path $imageitem){
$ie=new-Object -COMObject InternetExplorer.Application -Property @{Navigate2= $imageitem; Visible = $true}
$ie
sleep -Seconds $duration
$ie.Quit()
}
}
}