Results 1 to 4 of 4

Thread: Powershell: To check a directory exists or not?

  1. #1
    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?

  2. #2
    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}

  3. #3
    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"
    }

  4. #4
    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

Similar Threads

  1. Check if URL exists (Java)
    By Kelvin Little in forum Software Development
    Replies: 7
    Last Post: 08-01-2010, 04:04 PM
  2. How to check if file exists in directory with Php
    By Zool in forum Software Development
    Replies: 3
    Last Post: 03-11-2009, 12:36 PM
  3. How to check if variable exists in C#
    By Hamlet in forum Software Development
    Replies: 3
    Last Post: 28-08-2009, 07:30 PM
  4. Check if database or table exists
    By Xan in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 04:53 PM
  5. How to Check File Exists or Not in Linux
    By Ettan in forum Software Development
    Replies: 0
    Last Post: 19-12-2008, 01:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,616,056.20446 seconds with 17 queries