在Internet Explorer上循环图像

问题描述 投票:0回答:1

我使用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()
}

}

powershell
1个回答
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()
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.