Add support for multiple paths to Join-Path

Multiple child paths can be specified via the new positional parameter -AdditionalChildPath.
This commit is contained in:
Dave Wyatt authored and Jason Shirk (POWERSHELL) committed 2016-08-31 13:48:31 -07:00
1 parent 77a37f7773
commit 22aac12c3e
2 files changed
+28 -2

No files matched your search

@@ -3,6 +3,7 @@ Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Text;
using System.Collections.ObjectModel;
using System.Management.Automation;
using Dbg = System.Management.Automation;
@@ -32,7 +33,16 @@ namespace Microsoft.PowerShell.Commands
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true)]
[AllowNull]
[AllowEmptyString]
public string ChildPath { get; set; } = String.Empty;
public string ChildPath { get; set; }
/// <summary>
/// Gets or sets additional childPaths to the command.
/// </summary>
[Parameter(Position = 2, Mandatory = false, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = true)]
[AllowNull]
[AllowEmptyString]
[AllowEmptyCollection]
public string[] AdditionalChildPath { get; set; } = Utils.EmptyArray<string>();
/// <summary>
/// Determines if the path should be resolved after being joined
@@ -55,6 +65,17 @@ namespace Microsoft.PowerShell.Commands
Path != null,
"Since Path is a mandatory parameter, paths should never be null");
string combinedChildPath = ChildPath;
// join the ChildPath elements
if (AdditionalChildPath != null)
{
foreach (string childPath in AdditionalChildPath)
{
combinedChildPath = SessionState.Path.Combine(combinedChildPath, childPath, CmdletProviderContext);
}
}
foreach (string path in Path)
{
// First join the path elements
@@ -64,7 +85,7 @@ namespace Microsoft.PowerShell.Commands
try
{
joinedPath =
SessionState.Path.Combine(path, ChildPath, CmdletProviderContext);
SessionState.Path.Combine(path, combinedChildPath, CmdletProviderContext);
}
catch (PSNotSupportedException notSupported)
{