If have this piece of code
if(Test-Path -Path $OUT)
{
Remove-Item $OUT -Recurse
}
New-Item -ItemType directory -Path $OUT
Sometimes
For completeness' sake: You can also use the safe and fast .NET methods:
if ([System.IO.Directory]::Exists($OUT)) {
[System.IO.Directory]::Delete($OUT, $true)
}
[System.IO.Directory]::CreateDirectory($OUT)
Note:
Depending on where you get the value of $OUT you might want to convert it to a full path first to make sure the .NET methods remove the correct directory (see @mklement0`s comment):
$fullPath = Convert-Path $OUT