Join-Path and Split-Path should not fail if the path does not exist on the current machine - by Kirk Munro

Status : 


Sign in
to vote
ID 779068 Comments
Status Active Workarounds
Type Suggestion Repros 4
Opened 2/12/2013 11:39:01 AM
Access Restriction Public


Join-Path and Split-Path both fail if they are joining or splitting file paths that use a drive letter that is not on the local machine.  Since PowerShell has Remoting as a core feature, it is not uncommon to do some work in a remote session and some work locally.  As a result, you may be processing paths that contain drive letters that exist on a remote machine but not on the local system.  If you need to use Join-Path or Split-Path on such a path, you will receive an error message that the drive does not exist.  This is very limiting for these otherwise highly useful cmdlets.

A scenario where you might want to do something with this: querying a remote machine to get the path for a file, processing it locally to get the containing folder, and then invoking Move-Item to move the file from remote machine 1 to remote machine 2.  If you don't have the same drive on the local system, the processing to get the containing folder work fails.
Sign in to post a comment.
Posted by Aaron Jensen on 11/12/2013 at 5:03 PM
Oh, and I replicated this in both PowerShell 2 and 3.
Posted by Aaron Jensen on 11/12/2013 at 5:02 PM
Just encountered this today:

    $resourcesRoot = 'D:\Resources'
    $keyringsPath = Join-Path $resourcesRoot 'Keyrings'

The above call to `Join-Path` fails on any machine that doesn't have a D: drive. Why does `Join-Path` care if a drive exists? Shouldn't it only check a drive if I use the `-Resolve` switch?

To workaround, use the `Path.Combine` method:

    $resourcesRoot = D:\Resources'
    $keyringsPath = [IO.Path]::Combine( $resourcesRoot, 'Keyrings' )
Posted by blabla2 on 10/28/2013 at 1:54 AM
Join-Path doesn't work in powershell v4 if the folder doesn't exist.
Posted by Roman Kuzmin on 2/21/2013 at 9:55 AM
For me: split-path works in v3, join-path fails.
Posted by Stephen Mills on 2/20/2013 at 10:50 PM
I tried this in V3 and it worked for me. It didn't matter if I had the drive letter or not. Did you try it in V2 instead? This bug does exist there.