WiredWX Christian Hobby Weather Tools
Would you like to react to this message? Create an account in a few clicks or log in to continue.

WiredWX Christian Hobby Weather ToolsLog in

 


descriptionVerifying the Existence of a File or Folder From PowerShell EmptyVerifying the Existence of a File or Folder From PowerShell

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

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

descriptionVerifying the Existence of a File or Folder From PowerShell EmptyRe: Verifying the Existence of a File or Folder From PowerShell

more_horiz
Updated tutorial for added word. Thumb Up 4
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum