< Back
ConvertTo-ShortenedPath
Post
NAME ConvertTo-ShortenedPath
SYNOPSIS
Path Shortener
SYNTAX
ConvertTo-ShortenedPath [[-Path] <String>] [-KeepBefore <Int32>] [-KeepAfter <Int32>] [-MaxSegmentLength
<Nullable`1>] [-TruncateFirstSegment] [-TruncateLastSegment] [-TruncateCharacter <String>] [-ReplaceHome]
[-HomeCharacter <String>] [-Separator <String>] [-OutputSeparator <Nullable`1>] [<CommonParameters>]
DESCRIPTION
Function to convert paths to a shortend form.
Usefull in prompts to keep the total path length down.
PARAMETERS
-Path <String>
The path to shorten. Defaults to the current location.
Required? false
Position? 1
Default value (Get-Location)
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-KeepBefore <Int32>
Number of segments to keep before truncating. Default value is 2.
Required? false
Position? named
Default value 2
Accept pipeline input? false
Accept wildcard characters? false
-KeepAfter <Int32>
Number of segments to keep after truncating. Default value is 1.
Required? false
Position? named
Default value 1
Accept pipeline input? false
Accept wildcard characters? false
-MaxSegmentLength <Nullable`1>
Maximum length of each segment. If set, will truncate each path segment to the desired length.
Default value is null, which means no truncating of the segments will take place.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-TruncateFirstSegment [<SwitchParameter>]
Choose whether to truncate the first path segment or not. Default value is false.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-TruncateLastSegment [<SwitchParameter>]
Choose whether to truncate the last path segment or not. Default value is false.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-TruncateCharacter <String>
Character(s) to use in place of the truncated path segments.
Default value is '[char]8230' (horizontal ellipsis).
Required? false
Position? named
Default value ???????
Accept pipeline input? false
Accept wildcard characters? false
-ReplaceHome [<SwitchParameter>]
Choose whether to replace the home path. If set will replace the home path
with the value of the HomeReplacementCharacter parameter.
Default value is true.
Required? false
Position? named
Default value True
Accept pipeline input? false
Accept wildcard characters? false
-HomeCharacter <String>
Character(s) to use as replacement for the home path. Default value is '~'.
Required? false
Position? named
Default value ~
Accept pipeline input? false
Accept wildcard characters? false
-Separator <String>
Path separator character.
Defaults to DirectorySeparatorChar from the System.IO.Path class.
Required? false
Position? named
Default value [System.IO.Path]::DirectorySeparatorChar
Accept pipeline input? false
Accept wildcard characters? false
-OutputSeparator <Nullable`1>
Custom separator in the shortened path.
If set, the path separator character will be replaced with this in the output string.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
OUTPUTS
SYstem.String
NOTES
Rewrite of my old function 'Invoke-PathShortener'
Author: ????yvind Kallstad
Date: 13.05.2017
Version: 1.0
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>ConvertTo-ShortenedPath
Will shorten the current path, using default parameter values.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$path | ConvertTo-ShortenedPath -ReplaceHome:$false
Will shorten the path in the $path variable. The home path will not be replaced.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>ConvertTo-ShortenedPath -Path $pwd -MaxSegmentLength 1
Will shorten the current path, while truncating all but the first and last
path segments to just one character.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>ConvertTo-ShortenedPath -Path $pwd -MaxSegmentLength 1 -TruncateFirstSegment
Will shorten the current path, while truncating all but the last
path segment to just one character.
RELATED LINKS
https://communary.net/
SYNOPSIS
Path Shortener
SYNTAX
ConvertTo-ShortenedPath [[-Path] <String>] [-KeepBefore <Int32>] [-KeepAfter <Int32>] [-MaxSegmentLength
<Nullable`1>] [-TruncateFirstSegment] [-TruncateLastSegment] [-TruncateCharacter <String>] [-ReplaceHome]
[-HomeCharacter <String>] [-Separator <String>] [-OutputSeparator <Nullable`1>] [<CommonParameters>]
DESCRIPTION
Function to convert paths to a shortend form.
Usefull in prompts to keep the total path length down.
PARAMETERS
-Path <String>
The path to shorten. Defaults to the current location.
Required? false
Position? 1
Default value (Get-Location)
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-KeepBefore <Int32>
Number of segments to keep before truncating. Default value is 2.
Required? false
Position? named
Default value 2
Accept pipeline input? false
Accept wildcard characters? false
-KeepAfter <Int32>
Number of segments to keep after truncating. Default value is 1.
Required? false
Position? named
Default value 1
Accept pipeline input? false
Accept wildcard characters? false
-MaxSegmentLength <Nullable`1>
Maximum length of each segment. If set, will truncate each path segment to the desired length.
Default value is null, which means no truncating of the segments will take place.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-TruncateFirstSegment [<SwitchParameter>]
Choose whether to truncate the first path segment or not. Default value is false.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-TruncateLastSegment [<SwitchParameter>]
Choose whether to truncate the last path segment or not. Default value is false.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-TruncateCharacter <String>
Character(s) to use in place of the truncated path segments.
Default value is '[char]8230' (horizontal ellipsis).
Required? false
Position? named
Default value ???????
Accept pipeline input? false
Accept wildcard characters? false
-ReplaceHome [<SwitchParameter>]
Choose whether to replace the home path. If set will replace the home path
with the value of the HomeReplacementCharacter parameter.
Default value is true.
Required? false
Position? named
Default value True
Accept pipeline input? false
Accept wildcard characters? false
-HomeCharacter <String>
Character(s) to use as replacement for the home path. Default value is '~'.
Required? false
Position? named
Default value ~
Accept pipeline input? false
Accept wildcard characters? false
-Separator <String>
Path separator character.
Defaults to DirectorySeparatorChar from the System.IO.Path class.
Required? false
Position? named
Default value [System.IO.Path]::DirectorySeparatorChar
Accept pipeline input? false
Accept wildcard characters? false
-OutputSeparator <Nullable`1>
Custom separator in the shortened path.
If set, the path separator character will be replaced with this in the output string.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
OUTPUTS
SYstem.String
NOTES
Rewrite of my old function 'Invoke-PathShortener'
Author: ????yvind Kallstad
Date: 13.05.2017
Version: 1.0
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>ConvertTo-ShortenedPath
Will shorten the current path, using default parameter values.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$path | ConvertTo-ShortenedPath -ReplaceHome:$false
Will shorten the path in the $path variable. The home path will not be replaced.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>ConvertTo-ShortenedPath -Path $pwd -MaxSegmentLength 1
Will shorten the current path, while truncating all but the first and last
path segments to just one character.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>ConvertTo-ShortenedPath -Path $pwd -MaxSegmentLength 1 -TruncateFirstSegment
Will shorten the current path, while truncating all but the last
path segment to just one character.
RELATED LINKS
https://communary.net/