- PowerShell Tutorial
- PowerShell - Home
- PowerShell - Overview
- PowerShell - Environment Setup
- PowerShell - Cmdlets
- PowerShell - Files and Folders
- PowerShell - Dates and Timers
- PowerShell - Files I/O
- PowerShell - Advanced Cmdlets
- PowerShell - Scripting
- PowerShell - Special Variables
- PowerShell - Operators
- PowerShell - Looping
- PowerShell - Conditions
- PowerShell - Array
- PowerShell - Hashtables
- PowerShell - Regex
- PowerShell - Backtick
- PowerShell - Brackets
- PowerShell - Alias
- PowerShell Useful Resources
- PowerShell - Quick Guide
- PowerShell - Useful Resources
- PowerShell - Discussion
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
To Continue Learning Please Login
Login with Google