Verifying the Existence of a File or Folder From PowerShell
One of the primary uses of Test-Path is to verify the existence of a file or folder. For example, this command checks to see whether the file C:\Scripts\Test.txt exists:
Test-Path returns True if the file exists, and returns False if the file does not exist.
As is usually the case with cmdlets, you can use wildcards with Test-Path. For example, this script tells you whether or not there are any .wma files in C:\Scripts:
You can check for the existence of registry keys using Test-Path:
Code:
Test-Path c:\scripts\test.txt
Test-Path returns True if the file exists, and returns False if the file does not exist.
As is usually the case with cmdlets, you can use wildcards with Test-Path. For example, this script tells you whether or not there are any .wma files in C:\Scripts:
Code:
Test-Path c:\scripts\*.wma
You can check for the existence of registry keys using Test-Path:
Code:
Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion