![](/img/trans.png)
[英]Check if a file exist in appdata without adding the full path in the python code
[英]Check if file exist then continue with the code in Powershell
我需要檢查c:\\ pdf中是否存在某些pdf,如果存在則繼續執行,否則請每隔15秒再次檢查一次。
我的實際代碼只是檢查文件夾中的文件,並打印是否有東西,如果不是一遍又一遍的話。 我的問題是,有時我的代碼會在打印之前刪除項目,這就是為什么我要循環檢查文件並僅在存在文件的情況下繼續執行我的代碼的原因。
我的代碼:
Do {
$fileDirectory = "C:\pdf";
foreach($file in Get-ChildItem $fileDirectory)
{
$filePath = $fileDirectory + "\" + $file;
Start-Process –FilePath $filePath –Verb Print -WindowStyle Minimized -PassThru
}
Start-Sleep -s 2
Remove-Item c:\pdf\* -recurse
Get-Process AcroRd32 | % { $_.CloseMainWindow() }
sleep 15
} while ($true)
您可以只使用簡單的while塊:
While (!(Test-Path C:\pdf\file.pdf -ErrorAction SilentlyContinue))
{
# endless loop, when the file will be there, it will continue
}
# Next code block here #
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.