Verifying the Existence of a File or Folder From PowerShell
Please open the Command Prompt by simply by typing powershell into Start Menu search box. Right-click Windows PowerShell and select Run as Administrator. The UAC prompt will ask you for your consent. Click yes, and the prompt will open.


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:

Code:

Test-Path c:\scripts\test.txt


Test-Path returns True if the file exists, and returns False if the file does not exist.

The wildcards can be use with Test-Path cmdlet command. For example, this script tells you whether or not there are any .wma files in C:\Scripts:

Code:

Test-Path c:\scripts\*.wma


Existence of registry keys can be check with using Test-Path cmdlet command.

Code:

Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion