Home Check if file exist then continue with the code in Powershell
Reply: 0

Check if file exist then continue with the code in Powershell

user858
1#
user858 Published in July 21, 2018, 2:58 pm

I need to check if some pdf exists in c:\pdf and if exists continue with the execution, if not, check again every 15th second.

My actual code just checks for files in the folder and print if there is something, if not just repeat again and again. My problem is that sometimes my code deletes the items before printing, thats why I want to loop in the file check and only continue with my code, if a file exists.

My code:

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)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319745 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO