Add -Extension parameter to Join-Path cmdlet by yotsuda · Pull Request #26482 · PowerShell/PowerShell
added 2 commits
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
added
the
CL-General
label
- 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
- 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)
- 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
- 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
- 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
yotsuda
deleted the
feature/join-path-extension
branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters