PowerShell provides the
Join-Path cmdlet in order to combine paths. The Join-Path can be used to join or concatenate two or more paths together. Paths can be specified as strings. We can join path information like path, child path, drive, etc. by using the Join-Path command.
Combine Path with Child Path
The Join-Path command can be used with the
-ChildPath parameters. The -Path parameter is used to specify the parent or normal path which is located at the start of the joined path. In the following example, we set the “C:\Users” as the path and “ismail” as the child path.
PS> Join-Path -Path "C:\Users" -ChildPath "ismail"
Combine Path with Separator
Another useful feature of the Join-Path command is the ability to check separators and add them automatically. This prevents errors about separators like using them multiple times or joining paths without separators.
PS> Join-Path -Path "C:\Users\" -ChildPath "\ismail"
Display Files and Folders By Joining
We can display files and folders by joining them. This is very similar to the listing of the files.
PS> Join-Path "C:\win*" "System*" -Resolve
Combine More Than 2 Paths
Another useful feature of the Join-Path command is the ability to join multiple paths which are more than 2. In the following example, we are joining 4 paths.
PS> Join-Path "C:\" "Users" "ismail" Desktop"