Check if Folder Exists using Windows PowerShell

Easily verify the existence of a folder using PowerShell’s Test-Path cmdlet. Learn the simple steps to check if a folder exists on your system.

To check if a folder exists using PowerShell, you can use the Test-Path cmdlet. This cmdlet returns a Boolean value indicating whether the specified item exists.

Here is an example:

$folderPath = "C:\folder"

if (Test-Path $folderPath) {
    Write-Host "The folder exists."
} else {
    Write-Host "The folder does not exist."
}

In this example, $folderPath holds the path to the folder you want to check for. The Test-Path cmdlet is used to test if the folder exists, and the result is used in an if statement to output either “The folder exists.” or “The folder does not exist.” depending on the result.


Leave a Reply

Up ↑

Discover more from JD Bots

Subscribe now to keep reading and get access to the full archive.

Continue reading