◐ Shell
clean mode source ↗

Add -Extension parameter to Join-Path cmdlet by yotsuda · Pull Request #26482 · PowerShell/PowerShell

added 2 commits

November 19, 2025 09:14
This adds a new -Extension parameter to Join-Path that allows changing
the file extension of the resulting path, providing parity with
Split-Path's extension handling capabilities.

Features:
- Change extension: Join-Path -Path C:\folder -ChildPath file.txt -Extension .log
- Add extension: Join-Path -Path C:\folder -ChildPath file -Extension .txt
- Remove extension: Join-Path -Path C:\folder -ChildPath file.txt -Extension ''
- Supports pipeline input via ValueFromPipelineByPropertyName

Fixes PowerShell#20724

iSazonov

@iSazonov iSazonov added the CL-General

Indicates that a PR should be marked as a general cmdlet change in the Change Log

label

Nov 19, 2025
…nt/CombinePathCommand.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nt/CombinePathCommand.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Use string.TrimEnd('.') instead of Substring for cleaner code
- Remove redundant EndsWith check
- Add tests for multiple dots, directory-like paths, and multiple child paths
…nt/CombinePathCommand.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use $SepChar variable instead of hardcoded backslashes in test
expectations to ensure tests pass on both Windows and Unix platforms.

iSazonov

brianary

- Simplify extension logic: use ternary operator to pass null when empty
- Remove TrimEnd('.'): fixes issue where dots in base name were removed
- Add test cases for preserving dots in base name:
  * When removing extension (file...txt -> file..)
  * When changing extension (file...txt -> file...md)

iSazonov

…nt/CombinePathCommand.cs

Co-authored-by: Ilya <darpa@yandex.ru>
- Consolidate individual extension tests into TestCases for better maintainability
- Add test cases for extension without leading dot ('txt')
- Add test cases for double extensions ('.tar.gz', 'tar.gz')
- Remove duplicate test that is now covered by TestCases

Addresses review feedback from @iSazonov
- Add [ValidateNotNull] attribute to prevent explicit null values
- Update XML comment to clarify default behavior when Extension is not specified

Addresses review feedback from @iSazonov

iSazonov

- Remove Path from TestCases as it's constant across all tests
- Rename ExpectedResult to ExpectedChildPath for clarity
- Build full path in test body using 'folder' directly

Addresses review feedback from @iSazonov

iSazonov

- Consolidate six individual tests into TestCases arrays
- Tests for removing/changing extensions are now part of parameterized tests
- Created separate TestCases group for multiple child path segments
- This improves consistency and maintainability

Addresses review feedback from @iSazonov

iSazonov

@yotsuda yotsuda deleted the feature/join-path-extension branch

November 22, 2025 13:52

SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request

Dec 12, 2025

kilasuit pushed a commit to kilasuit/PowerShell that referenced this pull request

Jan 2, 2026

JustinGrote pushed a commit to JustinGrote/PowerShell that referenced this pull request

Jun 2, 2026