Monday, November 20, 2017

Check if Directory or Path Exists using Powershell and Windows Command (bat)

1. Via Powershell:

$DIRE = "C:\Temp"

if ( Test-Path $DIRE ) {
    echo "Directory Exists"
} else {
    md $DIRE 
}

Check 2 paths:

$source="C:\Temp"
$dest="K:\Temp"

if ( ( Test-Path $source ) -and ( Test-Path $dest ) ) {
     Write-Host "START Write to $dest";
}
else
{
     Write-Host "CAN NOT ACCESS Source or Dest: $dest";
}


2. Via Cmd:


IF EXIST C:\NUL ECHO C: Drive is availablae
IF EXIST C:\Temp\NUL ECHO C:\Temp is availablae

No comments:

Post a Comment