Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-02-2009
Member
 
Join Date: Jan 2009
Posts: 38
Powershell: To check a directory exists or not?

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?
Reply With Quote
  #2  
Old 18-02-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Powershell: To check a directory exists or not?

Assuming you're looking for the directory "test" in the current working directory:

if(!(test-path test -pathtype container)){new-item test -type directory}
Reply With Quote
  #3  
Old 18-02-2009
Member
 
Join Date: May 2008
Posts: 115
Re: Powershell: To check a directory exists or not?

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"
}
Reply With Quote
  #4  
Old 18-02-2009
Member
 
Join Date: May 2008
Posts: 40
Re: Powershell: To check a directory exists or not?

To check if a directory exists in a bash shell script you can use the following:

Code:
if [ -d "$DIRECTORY" ]; then
    # Will enter here if $DIRECTORY exists
fi
Or to check if a directory doesn't exist:

Code:
if [ ! -d "$DIRECTORY" ]; then
    # Will enter here if $DIRECTORY doesn't exist
fi
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Powershell: To check a directory exists or not?"
Thread Thread Starter Forum Replies Last Post
Check if URL exists (Java) Kelvin Little Software Development 7 08-01-2010 04:04 PM
How to check if file exists in directory with Php Zool Software Development 3 03-11-2009 12:36 PM
How to check if variable exists in C# Hamlet Software Development 3 28-08-2009 07:30 PM
Check if database or table exists Xan Software Development 2 29-05-2009 04:53 PM
How to Check File Exists or Not in Linux Ettan Software Development 0 19-12-2008 01:42 PM


All times are GMT +5.5. The time now is 01:15 PM.