Thursday, 12 March 2015

Powershell – Check If File Exists or Not

We can check and test if a file or folder exist or not by using the PowerShell cmdlet Test-Path.

The below powershell script will check whether the file test.txt is already exists or not under the path C:\Share\.
$FileName = "C:\Share\test.txt"
if (Test-Path $FileName) 
{
  Write-Host "File Exists"
}
else
{
  Write-Host "File Not Exists"
}

Advertisements
Advertisements

No comments:

Post a Comment