Split-Path serendipity

I’ve used Split-Path and its associated cmdlet Join-Path a lot when working with file system paths. Something I read today started me asking if it would work with URLs

 

It does:

 

£> Split-Path -Path 'http://powershell.org/wp/forums/forum/windows-powershell-qa/' -Leaf
windows-powershell-qa


£> Split-Path -Path 'http://powershell.org/wp/forums/forum/windows-powershell-qa/' -Parent
http:\\powershell.org\wp\forums\forum

 

£> Split-Path -Path 'http://powershell.org/wp/forums/forum/windows-powershell-qa/' -NoQualifier
//powershell.org/wp/forums/forum/windows-powershell-qa/


£> Split-Path -Path 'http://powershell.org/wp/forums/forum/windows-powershell-qa/' -Qualifier
http:

 

The –Resolve parameter won’t work because its not a file system path but if you need to play with URLs then could be useful.

 

Just for completeness Join-Path won’t work with URLs because its attempting to resolve the file path

Leave a Reply