PowerShell / Microsoft.PowerShell.Archive

Archive PowerShell module contains cmdlets for working with ZIP archives
https://technet.microsoft.com/en-us/library/dn818910.aspx
MIT License
94 stars 37 forks source link

Can't extract in directory with brackets in directory name #115

Closed GeneralBouLi closed 2 years ago

GeneralBouLi commented 3 years ago

Prerequisites

Steps to reproduce

Execute : Expand-Archive -Path "$ZIP_DIRECTORY\$ZIP_NAME" -DestinationPath "C:\$UNZIP_DIRECTORY[TEST]"

No problem with : Expand-Archive -Path "$ZIP_DIRECTORY\$ZIP_NAME" -DestinationPath "C:\$UNZIP_DIRECTORY\TEST"

Expected behavior

Unzip in directory [TEST]

Actual behavior

New-Item: An item with the specified name C:\$UNZIP_DIRECTORY\[TEST] already exists.

Error details

New-Item: An item with the specified name C:\$UNZIP_DIRECTORY\[TEST] already exists.

Environment data

Win10 + Powershell 7.2

Visuals

No response

iSazonov commented 3 years ago

Related PowerShell/PowerShell#12168 ##6232

jhoneill commented 3 years ago

In .Net wildcards, [] are used to specify a selection, (similar to regular expressions) so dir "*.[pqr]s1" in Powershell will return .ps1, .qs1 and .rs1 files.
and dir *ps[0-9] will return .ps0, ps1 ... ps9

MANY things will treat [] as invalid, even though the file system allows them. So you get this sort of thing

 dir > 'test[1]'
Out-File: Cannot perform operation because the wildcard path test[1] did not resolve to a file.
 dir > 'test`[1`]' 

works and if use double quotes you need to double up the backquote.

Your code will work if you use -DestinationPath ([WildcardPattern]::Escape( "C:$UNZIP_DIRECTORY[TEST]"))

daxian-dbw commented 2 years ago

Expand-Archive may need to have path parameters like LiteralPath to support what's asked in the issue. @SteveL-MSFT can you please move the issue to the Archive repo?

SydneyhSmith commented 2 years ago

@SteveL-MSFT looks like this issue can be moved to the Archive repo