How to compare if a folder exists and if it does not exist, create her How to compare if a folder exists and if it does not exist, create her powershell powershell

How to compare if a folder exists and if it does not exist, create her


You could also use the New-Item cmdlet with the force parameter, you don't even have to check whether the directory exists:

New-Item -Path C:\tmp\test\abc -ItemType Directory -Force


Per the comments, Test-Path is the PowerShell cmdlet you should use to check for the existence of a file or directory:

$DIRE = "C:\DIRETORIO"if ( Test-Path $DIRE ) {    echo "Directory Exists"} else {    md DIRETORIO}

The Test-Path cmdlet determines whether all elements of the path exist. It returns $True if all elements exist and $False if any are missing. It can also tell whether the path syntax is valid and whether the path leads to a container or a terminal or leaf element.