Powershell - Check File Existence
Cmdlet
Test-Path cmdlet is used to check existence of a file.
Example 1
In this example, we're having a file test.txt in D:\temp\test directory
Type the following command in PowerShell ISE Console
Test-Path D:\temp\test\test.txt
Output
You can see following output in PowerShell console.
Test-Path D:\temp\test\test.txt True
Example 2
In this example, we're not having a file named test2.txt in D:\temp\test directory
Type the following command in PowerShell ISE Console
Test-Path D:\temp\test\test2.txt
Output
You can see following output in PowerShell console.
Test-Path D:\temp\test\test2.txt False
powershell_files_folders.htm
Advertisements