PowerShell Logo Small

Split-Path



This is the built-in help made by Microsoft for the command 'Split-Path', in PowerShell version 4 - as retrieved from Windows version 'Microsoft Windows 8.1 Enterprise' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Returns the specified part of a path.

SYNTAX


Split-Path [-Path] <String[]> [-Credential <PSCredential>] [-Parent] [-Resolve] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Split-Path [-Path] <String[]> [-Credential <PSCredential>] [-IsAbsolute] [-Resolve] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Split-Path [-Path] <String[]> [-Credential <PSCredential>] [-Leaf] [-Resolve] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Split-Path [-Credential <PSCredential>] [-Resolve] -LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Split-Path [-Path] <String[]> [-Credential <PSCredential>] [-NoQualifier] [-Resolve] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]
Split-Path [-Path] <String[]> [[-Qualifier]] [-Credential <PSCredential>] [-Resolve] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Split-Path cmdlet returns only the specified part of a path, such as the parent directory, a child directory, or a file name. It can also get items that are refer
enced by the split path and tell whether the path is relative or absolute.


You can use this cmdlet to get or submit only a selected part of a path.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293917
Convert-Path
Join-Path
Resolve-Path
Test-Path
about_Providers

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>split-path "HKCU:\Software\Microsoft" -qualifier
HKCU:



This command returns only the qualifier (the drive) of the path.








-------------------------- EXAMPLE 2 --------------------------

PS C:\>split-path "C:\Test\Logs\*.log" -leaf -resolve
Pass1.log
Pass2.log
...



This command displays the files that are referenced by the split path. Because this path is split to the last item (the "leaf"), only the file names of the paths are
displayed.

The Resolve parameter tells Split-Path to display the items that the split path references, instead of displaying the split path.

Like all Split-Path commands, this command returns strings. It does not return FileInfo Objects representing the files.








-------------------------- EXAMPLE 3 --------------------------

PS C:\>split-path "C:\WINDOWS\system32\WindowsPowerShell\V1.0\about_*.txt"
C:\WINDOWS\system32\WindowsPowerShell\V1.0



This command returns only the parent containers of the path. Because it does not include any parameters to specify the split, Split-Path uses the split location defau
lt, which is Parent.








-------------------------- EXAMPLE 4 --------------------------

PS C:\>split-path ".\My Pictures\*.jpg" -IsAbsolute
False



This command determines whether the path is relative or absolute. In this case, because the path is relative to the current directory, which is represented by a dot (
.), it returns FALSE ($false).








-------------------------- EXAMPLE 5 --------------------------

PS C:\>set-location (split-path $profile)
PS C:\Documents and Settings\User01\My Documents\WindowsPowerShell>



This command changes your location to the directory that contains the Windows PowerShell profile.

The command in parentheses uses the Split-Path cmdlet to return only the parent of the path stored in the built-in $Profile variable. (The Parent parameter is the def
ault split location parameter, so you can omit it from the command.) The parentheses direct Windows PowerShell to run the command first. This is a handy way to naviga
te to a directory with a long path name.








-------------------------- EXAMPLE 6 --------------------------

PS C:\>'C:\Documents and Settings\User01\My Documents\My Pictures' | split-path
C:\Documents and Settings\User01\My Documents



This command uses a pipeline operator (|) to send a path to the Split-Path cmdlet. The path is enclosed in quotation marks to indicate that it is a single token.