I want to check if a directory or folder exist or not with Powershell?
Is there any simple way to find it out with Powershell?
I want to check if a directory or folder exist or not with Powershell?
Is there any simple way to find it out with Powershell?
Assuming you're looking for the directory "test" in the current working directory:
if(!(test-path test -pathtype container)){new-item test -type directory}
Add the '-errorAction silentlyContinue' to avoid the error message in case the folder doesn't exist:
if (Get-PublicFolder "\Locations\$Location" -errorAction silentlyContinue) {
Write-Warning "Folder $Location already exists!"
} else {
New-PublicFolder -Name $Location -Path "\Locations"
}
To check if a directory exists in a bash shell script you can use the following:
Or to check if a directory doesn't exist:Code:if [ -d "$DIRECTORY" ]; then # Will enter here if $DIRECTORY exists fi
Code:if [ ! -d "$DIRECTORY" ]; then # Will enter here if $DIRECTORY doesn't exist fi
Bookmarks