@@ -419,9 +419,10 @@ function Expand-Archive
419
419
}
420
420
elseif ($PassThru -and $expandedItems.Count -gt 0 )
421
421
{
422
- # Return the expanded items, being careful to remove trailing backslashes from
422
+ # Return the expanded items, being careful to remove trailing directory separators from
423
423
# any folder paths for consistency
424
- Get-Item - LiteralPath ($expandedItems -replace ' \\+$' )
424
+ $trailingDirSeparators = ' \' + [System.IO.Path ]::DirectorySeparatorChar + ' +$'
425
+ Get-Item - LiteralPath ($expandedItems -replace $trailingDirSeparators )
425
426
}
426
427
}
427
428
}
@@ -669,22 +670,22 @@ function CompressSingleDirHelper
669
670
$sourceDirInfo = New-Object - TypeName System.IO.DirectoryInfo - ArgumentList $sourceDirPath
670
671
$sourceDirFullName = $sourceDirInfo.Parent.FullName
671
672
672
- # If the directory is present at the drive level the DirectoryInfo.Parent include '\' example: C:\
673
+ # If the directory is present at the drive level the DirectoryInfo.Parent include directory separator. example: C:\
673
674
# On the other hand if the directory exists at a deper level then DirectoryInfo.Parent
674
- # has just the path (without an ending '\' ). example C:\source
675
+ # has just the path (without an ending directory separator ). example C:\source
675
676
if ($sourceDirFullName.Length -eq 3 )
676
677
{
677
678
$modifiedSourceDirFullName = $sourceDirFullName
678
679
}
679
680
else
680
681
{
681
- $modifiedSourceDirFullName = $sourceDirFullName + " \ "
682
+ $modifiedSourceDirFullName = $sourceDirFullName + [ System.IO.Path ]::DirectorySeparatorChar
682
683
}
683
684
}
684
685
else
685
686
{
686
687
$sourceDirFullName = $sourceDirPath
687
- $modifiedSourceDirFullName = $sourceDirFullName + " \ "
688
+ $modifiedSourceDirFullName = $sourceDirFullName + [ System.IO.Path ]::DirectorySeparatorChar
688
689
}
689
690
690
691
$dirContents = Get-ChildItem - LiteralPath $sourceDirPath - Recurse
@@ -704,7 +705,7 @@ function CompressSingleDirHelper
704
705
$files = $currentContent.GetFiles ()
705
706
if ($files.Count -eq 0 )
706
707
{
707
- $subDirFiles.Add ($currentContent.FullName + " \ " )
708
+ $subDirFiles.Add ($currentContent.FullName + [ System.IO.Path ]::DirectorySeparatorChar )
708
709
}
709
710
}
710
711
}
@@ -795,8 +796,8 @@ function ZipArchiveHelper
795
796
796
797
# If a directory needs to be added to an archive file,
797
798
# by convention the .Net API's expect the path of the diretcory
798
- # to end with '\' to detect the path as an directory.
799
- if (! $relativeFilePath.EndsWith (" \ " , [StringComparison ]::OrdinalIgnoreCase))
799
+ # to end with directory separator to detect the path as an directory.
800
+ if (! $relativeFilePath.EndsWith ([ System.IO.Path ]::DirectorySeparatorChar , [StringComparison ]::OrdinalIgnoreCase))
800
801
{
801
802
try
802
803
{
@@ -975,9 +976,9 @@ function ExpandArchiveHelper
975
976
$extension = [system.IO.Path ]::GetExtension($currentArchiveEntryPath )
976
977
977
978
# The current archive entry is an empty directory
978
- # The FullName of the Archive Entry representing a directory would end with a trailing '\' .
979
+ # The FullName of the Archive Entry representing a directory would end with a trailing directory separator .
979
980
if ($extension -eq [string ]::Empty -and
980
- $currentArchiveEntryPath.EndsWith (" \ " , [StringComparison ]::OrdinalIgnoreCase))
981
+ $currentArchiveEntryPath.EndsWith ([ System.IO.Path ]::DirectorySeparatorChar , [StringComparison ]::OrdinalIgnoreCase))
981
982
{
982
983
$pathExists = Test-Path - LiteralPath $currentArchiveEntryPath
983
984
0 commit comments