One liner code to check if file exists via PowerShell.
Code below will check if Winrar.exe exist on the path specified.
if (-not (test-path "$env:C:\Program Files\WinRAR\winrar.exe")) {write-host "File not found"; break;} {write-host "File Found" }
Output will show "File Found" if winrar.exe exists on the path specified.
The "break;" command on the code will cause the script to exit and not to continue to show "File Found" if the file doesn't exist. Or else it will be confusing to see the output. However, if the file can be found then the "File not Found" will not be shown. PowerShell will automatically bypass the first command on the { } curly braces and execute whatever is on the next line.
Code below will check if output.txt exist on c:\temp.
if (-not (test-path "$env:C:\temp\output.txt")) {write-host "File not found"; break;} {write-host "File Found" }
Output will show "File Found" if output.txt exists on the path specified else it will show "File not Found".
If the path or folder is incorrect, then code will show "File not Found" since the path is wrong.
If the path is correct or the folder on the path also exists, but the file cannot be found then the code will show "file not found".
Till next time. Cheers! God bless and stay safe.
Do ASAP, Always Say A Prayer...
Practice O.T.G. = Obedience To God
================================
Free Android Apps:
Click links below to find out more:
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
Divine Mercy Chaplet Guide (A Powerful prayer) BFF = Be Filled Faith:
https://play.google.com/store/apps/details?id=com.dmercyapp
Comments
Post a Comment