-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathCurrent.directory.with.odd.name.ps1
45 lines (35 loc) · 1.16 KB
/
Current.directory.with.odd.name.ps1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# results to be shown and tested
$results = New-Object System.Collections.Specialized.OrderedDictionary
# this script directory
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Definition
# makes a directory and a directory 'test' in it
function New-TestDirectory($Path) {
$test = "$Path/test"
if (![System.IO.Directory]::Exists($test)) {$null = mkdir $test}
}
### test 1, cd `[1] and test `[1]\test
$odd = Join-Path $PSScriptRoot '`[1]'
New-TestDirectory $odd
Set-Location -LiteralPath $odd
# the current path
$results.Location1 = (Get-Location).Path
# the item 'test' is there
$results.GetChildItem1 = Get-ChildItem
# $false, expected $true
$results.TestPathNormal1 = Test-Path test
# $false, expected $true
$results.TestPathLiteral1 = Test-Path -LiteralPath test
### test 2, cd [1] and test [1]\test
$odd = Join-Path $PSScriptRoot '[1]'
New-TestDirectory $odd
Set-Location -LiteralPath $odd
# the current path
$results.Location2 = (Get-Location).Path
# the item 'test' is there
$results.GetChildItem2 = Get-ChildItem
# $true, correct
$results.TestPathNormal2 = Test-Path test
# $false, expected $true
$results.TestPathLiteral2 = Test-Path -LiteralPath test
# output
$results