Skip to content

Commit

Permalink
Add Join-Path/With-path-separator, close #20
Browse files Browse the repository at this point in the history
  • Loading branch information
nightroman committed Oct 3, 2024
1 parent 4f60067 commit 796cbbb
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 17 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# `Join-Path` fails if the path drive does not exist

The script [Test-missing-drive.ps1](Test-missing-drive.ps1) finds a missing drive and uses it in order
to join paths by the .NET method `Path.Combine()` (works) and by PowerShell
cmdlet `Join-Path` (fails).

### Join-Path with UNC paths: mind the current provider

When `Join-Path` is used with UNC paths then the results may depend on the
current provider. If it is accidentally not *FileSystem* then it may be a
mistake. The script [Test-mind-the-provider.ps1](Test-mind-the-provider.ps1) shows the issue.

---

- [Split-Path](../Split-Path)
- Microsoft Connect 779068
# `Join-Path` fails if the path drive does not exist

The script [Test-missing-drive.ps1](Test-missing-drive.ps1) finds a missing drive and uses it in order
to join paths by the .NET method `Path.Combine()` (works) and by PowerShell
cmdlet `Join-Path` (fails).

### Join-Path with UNC paths: mind the current provider

When `Join-Path` is used with UNC paths then the results may depend on the
current provider. If it is accidentally not *FileSystem* then it may be a
mistake. The script [Test-mind-the-provider.ps1](Test-mind-the-provider.ps1) shows the issue.

---

- [Split-Path](../../Split-Path)
- Microsoft Connect 779068
File renamed without changes.
12 changes: 12 additions & 0 deletions Cmdlets/Join-Path/With-path-separator/.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

task test {
$1, $2 = ./Test-1.ps1
if ($PSEdition -eq 'Desktop') {
equals $1 C:\Test\Test\
equals $2 Test\Test\
}
else {
equals $1 C:/Test/Test/\
equals $2 Test/Test/\
}
}
14 changes: 14 additions & 0 deletions Cmdlets/Join-Path/With-path-separator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `Join-Path` with path separator

Use case: some applications require trailing path separators for input directory paths.

`Join-Path` with `\` or `/` as the second argument may be used in order to
ensure this requirement in Windows PowerShell. In PowerShell Core results
may be unexpected.

The script [Test-1.ps1](Test-1.ps1) shows some cases with differences.

---

- [PowerShell/issues/24193](https://github.com/PowerShell/PowerShell/issues/24193)
- [PowerShellTraps/issues/20](https://github.com/nightroman/PowerShellTraps/issues/20)
8 changes: 8 additions & 0 deletions Cmdlets/Join-Path/With-path-separator/Test-1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# 5.1 : C:\Test\Test\
# 7.x : C:/Test/Test/\
Join-Path 'C:/Test/Test/' '\'

# 5.1 : Test\Test\
# 7.x : Test/Test/\
Join-Path 'Test/Test/' '/'
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ to their directory. See also [TESTS]. Some scripts require
- [`Invoke-Expression` `ErrorAction` is ignored in favour of `$ErrorActionPreference`](Cmdlets/Invoke-Expression/ErrorAction)
- Invoke-RestMethod
- [`Invoke-RestMethod` returns an array not unrolled](Cmdlets/Invoke-RestMethod/Not-unrolled-result)
- [`Join-Path` fails if the path drive does not exist](Cmdlets/Join-Path)
- Join-Path
- [`Join-Path` fails if the path drive does not exist](Cmdlets/Join-Path/Drive-does-not-exist)
- [`Join-Path` with path separator](Cmdlets/Join-Path/With-path-separator)
- Read-Host
- [v5 output before `Read-Host`](Cmdlets/Read-Host/v5-Output-before-Read-Host)
- Remove-Item
Expand Down

0 comments on commit 796cbbb

Please sign in to comment.