Basics with Windows Power Shell by Prometheus MMS - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

2.7 Verifying the Existence of a File or Folder

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 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:

Test-Path c:\scripts\*.wma

Did someone ask if you can you check for the existence of registry keys using Test-Path? Of course you can:

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

Find Your Next Great Read

Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.

Showing results for ""

Popular searches:

Romance Mystery & Thriller Self-Help Sci-Fi Business