I am trying to create a folder using PowerShell if it does not exists so I did :
$DOCDIR = [Environment]::GetFolderPath("MyDocuments")
$TARGETDIR = "$DOCDIR\MatchedLog"
if(!(Test-Path -Path MatchedLog )){
New-Item -ItemType directory -Path $DOCDIR\MatchedLog
}
This is giving me error that the folder already exists, which it does but It shouldn't be trying to create it.
I am not sure what's wrong here
New-Item : Item with specified name C:\Users\l\Documents\MatchedLog already exists. At C:\Users\l\Documents\Powershell\email.ps1:4 char:13 + New-Item <<<< -ItemType directory -Path $DOCDIR\MatchedLog + CategoryInfo : ResourceExists: (C:\Users\l....ents\MatchedLog:String) [New-Item], IOException + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand`