Split-Path
Returns the specified part of a path.
구문
ParentSet (기본값)
Split-Path
[-Path] <String[]>
[-Parent]
[-Resolve]
[-Credential <PSCredential>]
[-UseTransaction]
[<CommonParameters>]
NoQualifierSet
Split-Path
[-Path] <String[]>
[-NoQualifier]
[-Resolve]
[-Credential <PSCredential>]
[-UseTransaction]
[<CommonParameters>]
LeafSet
Split-Path
[-Path] <String[]>
[-Leaf]
[-Resolve]
[-Credential <PSCredential>]
[-UseTransaction]
[<CommonParameters>]
QualifierSet
Split-Path
[-Path] <String[]>
[-Qualifier]
[-Resolve]
[-Credential <PSCredential>]
[-UseTransaction]
[<CommonParameters>]
IsAbsoluteSet
Split-Path
[-Path] <String[]>
[-Resolve]
[-IsAbsolute]
[-Credential <PSCredential>]
[-UseTransaction]
[<CommonParameters>]
LiteralPathSet
Split-Path
-LiteralPath <String[]>
[-Resolve]
[-Credential <PSCredential>]
[-UseTransaction]
[<CommonParameters>]
Description
The Split-Path
cmdlet returns only the specified part of a path, such as the parent folder, a
subfolder, or a filename. It can also get items that are referenced 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.
예제
Example 1: Get the qualifier of a path
Split-Path -Path "HKCU:\Software\Microsoft" -Qualifier
HKCU:
This command returns only the qualifier of the path. The qualifier is the drive.
Example 2: Display filename portion of the path
When using the Leaf parameter, Split-Path
returns only the last item in the path string
supplied, regardless whether that item is a file or a directory.
Split-Path -Path .\folder1\*.txt -Leaf
*.txt
Split-Path -Path .\folder1\*.txt -Leaf -Resolve
file1.txt
file2.txt
When you use the Resolve parameter, Split-Path
resolves the path string provided and returns
the items referenced by the path.
Example 3: Get the parent container
When using the Parent parameter, Split-Path
returns only the parent container portion of the
path string supplied. If the Path string doesn't contain a parent container, Split-Path
returns an empty string.
Split-Path -Path .\folder1\file1.txt -Parent
.\folder1
Split-Path -Path .\folder1\file1.txt -Parent -Resolve
D:\temp\test\folder1
When you use the Resolve parameter, Split-Path
resolves the path string provided and returns
the full path of the parent container.
Example 4: Determines whether a path is absolute
This command determines whether the path is relative or absolute. In this case, because the path is
relative to the current folder, which is represented by a dot (.
), it returns $false
.
Split-Path -Path ".\My Pictures\*.jpg" -IsAbsolute
False
Example 5: Change ___location to a specified path
This command changes your ___location to the folder that contains the PowerShell profile.
PS C:\> Set-Location (Split-Path -Path $PROFILE)
PS C:\Users\User01\Documents\PowerShell>
The command in parentheses uses Split-Path
to return only the parent of the path stored in the
built-in $PROFILE
variable. The Parent parameter is the default split ___location parameter.
Therefore, you can omit it from the command. The parentheses direct PowerShell to run the command
first. This is a useful way to move to a folder that has a long path name.
Example 6: Split a path using the pipeline
'C:\Users\User01\My Documents\My Pictures' | Split-Path
C:\Users\User01\My Documents
This command uses a pipeline operator (|
) to send a path to Split-Path
. The path is enclosed in
quotation marks to indicate that it's a single token.
매개 변수
-Credential
Note
This parameter isn't supported by any providers installed with PowerShell. To impersonate another user, or elevate your credentials when running this cmdlet, use Invoke-Command.
매개 변수 속성
형식: | PSCredential |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-IsAbsolute
Indicates that this cmdlet returns $true
if the path is absolute and $false
if it's relative. On
Windows, an absolute path string must start with a provider drive specifier, like C:
or HKCU:
. A
relative path starts with a dot (.
) or a dot-dot (..
).
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
IsAbsoluteSet
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
-Leaf
When using the Leaf parameter, Split-Path
returns only the last item in the path string
supplied, regardless whether that item is a file or a directory.
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
LeafSet
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-LiteralPath
Specifies the paths to be split. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcard characters. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
매개 변수 속성
형식: | String[] |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
별칭: | PSPath |
매개 변수 집합
LiteralPathSet
Position: | Named |
필수: | True |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-NoQualifier
Indicates that this cmdlet returns the path without the qualifier. For the FileSystem or registry
providers, the qualifier is the drive of the provider path, such as C:
or HKCU:
. For example, in the
path C:\Test\Logs\Pass1.log
, it returns only \Test\Logs\Pass1.log
.
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
NoQualifierSet
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-Parent
Split-Path
returns only the parent container portion of the path string supplied. If the Path
string doesn't contain a parent container, Split-Path
returns an empty string.
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
ParentSet
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-Path
Specifies the paths to be split. Wildcard characters are permitted. If the path includes spaces, enclose it in quotation marks. You can also pipe a path to this cmdlet.
매개 변수 속성
형식: | String[] |
Default value: | None |
와일드카드 지원: | True |
DontShow: | False |
매개 변수 집합
ParentSet
Position: | 0 |
필수: | True |
파이프라인의 값: | True |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
NoQualifierSet
Position: | 0 |
필수: | True |
파이프라인의 값: | True |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
LeafSet
Position: | 0 |
필수: | True |
파이프라인의 값: | True |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
QualifierSet
Position: | 0 |
필수: | True |
파이프라인의 값: | True |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
IsAbsoluteSet
Position: | 0 |
필수: | True |
파이프라인의 값: | True |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-Qualifier
Indicates that this cmdlet returns only the qualifier of the specified path. For the FileSystem or
Registry providers, the qualifier is the drive of the provider path, such as C:
or HKCU:
.
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
QualifierSet
Position: | 1 |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | True |
나머지 인수의 값: | False |
-Resolve
Indicates that this cmdlet displays the items that are referenced by the resulting split path instead of displaying the path elements.
매개 변수 속성
형식: | SwitchParameter |
Default value: | None |
와일드카드 지원: | False |
DontShow: | False |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
-UseTransaction
Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.
매개 변수 속성
형식: | SwitchParameter |
Default value: | False |
와일드카드 지원: | False |
DontShow: | False |
별칭: | usetx |
매개 변수 집합
(All)
Position: | Named |
필수: | False |
파이프라인의 값: | False |
속성 이름별 파이프라인의 값: | False |
나머지 인수의 값: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
입력
String
You can pipe a string that contains a path to this cmdlet.
출력
String
This cmdlet returns text strings. When you specify the Resolve parameter, it returns a string that describes the ___location of the items. It doesn't return objects that represent the items, such as a FileInfo or RegistryKey object.
Boolean
When you specify the IsAbsolute parameter, this cmdlet returns a Boolean value.
참고
The split ___location parameters (Qualifier, Parent, Leaf, and NoQualifier) are exclusive. You can use only one in each command.
The cmdlets that contain the Path noun (the Path cmdlets) work with path names and return the names in a concise format that all PowerShell providers can interpret. They're designed for use in programs and scripts where you want to display all or part of a path name in a particular format. Use them in the way that you would use Dirname, Normpath, Realpath, Join, or other path manipulators.
You can use the Path cmdlets together with several providers. These include the FileSystem, Registry, and Certificate providers.
Split-Path
is designed to work with the data exposed by any provider. To list the providers available in your session, typeGet-PSProvider
. For more information, see about_Providers.