Join Path to Combine More Than Two Strings Into a File Path in PowerShell

The Join-Path
cmdlet allows the user to combine strings into a single path. Sometimes, you might need to combine paths to create a single path when working in PowerShell.
It is where the Join-Path
cmdlet comes into action. Many child paths can be combined or appended to the main path for creating a single path.
The -Path
parameter specifies the main path to which the child-path is appended. -Path
value determines which provider joins the paths and adds the path delimiters.
It provides the \
delimiter to join the paths. The -ChildPath
parameter specifies the paths to append to the -Path
parameter value.
For example, the following command uses Join-Path
to combine the main path hello
and a child-path world
.
Join-Path -Path "hello" -ChildPath "world"
Output:
hello\world
The Join-Path
cmdlet accepts only two string inputs or one -ChildPath
parameter. Using the single command, you cannot use Join-Path
to combine more than two strings into a file path.
You will need to use multiple Join-Path
statements together to combine more than two strings into a file path in PowerShell.
Use the Join-Path
Value to Combine More Than Two Strings Into a File Path in PowerShell
Since the Join-Path
path value can send down to the pipe, you can pipe multiple Join-Path
statements together to combine more than two strings into a file path.
For example, the following code combines all four strings and creates a single path C:\content\software\PowerShell
.
Join-Path -Path "C:" -ChildPath "content" | Join-Path -ChildPath "software" | Join-Path -ChildPath "PowerShell"
Output:
C:\content\software\PowerShell
Related Article - PowerShell String
- Array of Strings in PowerShell
- Check if a File Contains a Specific String Using PowerShell
- Extract a PowerShell Substring From a String
- Extract Texts Using Regex in PowerShell
- Generate Random Strings Using PowerShell
- Escape Single Quotes and Double Quotes in PowerShell
Related Article - PowerShell Path
- Access to the Path Is Denied in PowerShell
- Split Directory Path in PowerShell
- Path With Spaces in PowerShell