File: Ensure-Location.ps1

package info (click to toggle)
obs-gradient-source 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 440 kB
  • sloc: ansic: 425; makefile: 22; cpp: 16
file content (29 lines) | stat: -rwxr-xr-x 716 bytes parent folder | download | duplicates (47)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function Ensure-Location {
    <#
        .SYNOPSIS
            Ensures current location to be set to specified directory.
        .DESCRIPTION
            If specified directory exists, switch to it. Otherwise create it,
            then switch.
        .EXAMPLE
            Ensure-Location "My-Directory"
            Ensure-Location -Path "Path-To-My-Directory"
    #>

    param(
        [Parameter(Mandatory)]
        [string] $Path
    )

    if ( ! ( Test-Path $Path ) ) {
        $_Params = @{
            ItemType = "Directory"
            Path = ${Path}
            ErrorAction = "SilentlyContinue"
        }

        New-Item @_Params | Set-Location
    } else {
        Set-Location -Path ${Path}
    }
}