MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Other
1.98k stars 1.57k forks source link

Expand-Archive can't handle archives with some chars in filenames #6067

Closed skhodzhaev closed 4 years ago

skhodzhaev commented 4 years ago

Just a few examples of filenames: "E:\temp\Эберс Георг - Тернистым путем [Каракалла].zip" "E:\temp\Щербакова Галина - …Все это следует шить.zip" While Test-Path returns True, Expand-Archive throw an exception:

New-Object : Exception calling ".ctor" with "1" argument(s): "The given path's format is not supported."
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1001 char:52
+ ... yFileInfo = New-Object -TypeName System.IO.FileInfo -ArgumentList $cu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Looks like the problem characters are "[", "]" and "…"


Сведения о документе

Не вносите правки в этот раздел. Это необходимо для связывания страницы сайта docs.microsoft.com с вопросом на GitHub.

sdwheeler commented 4 years ago

I am not able to reproduce the problem. Can you show the exact command you are using?

You probably need to use the -LiteralPath parameter. For example:

Expand-Archive -Destination .\temp -LiteralPath 'E:\temp\Эберс Георг - Тернистым путем [Каракалла].zip'
skhodzhaev commented 4 years ago

LiteralPath does solve the "[" problem. Thanks. But doesn't solve the problem of "…" (ellipsis) character:

PS E:\temp>> [int][char]'…'
8230
PS E:\temp>> Test-Path 'e:\temp\177196….zip' 
True
PS E:\temp>> Expand-Archive -LiteralPath 'e:\temp\177196….zip' 
New-Object : Exception calling ".ctor" with "1" argument(s): "The given path's format is not supported."
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1001 char:52
+ ... yFileInfo = New-Object -TypeName System.IO.FileInfo -ArgumentList $cu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

PS E:\temp>> Expand-Archive -Path 'e:\temp\177196….zip' 
New-Object : Exception calling ".ctor" with "1" argument(s): "The given path's format is not supported."
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1001 char:52
+ ... yFileInfo = New-Object -TypeName System.IO.FileInfo -ArgumentList $cu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

My PowerShell version is:

PS E:\temp>> Get-Host
Name             : Windows PowerShell ISE Host
Version          : 5.1.18362.752
InstanceId       : 04ebe5cc-2c8f-4144-b162-c92fb80bce1b
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : ru-RU
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

My Windows is

PS E:\temp>> [System.Environment]::OSVersion
Platform ServicePack Version      VersionString                    
-------- ----------- -------      -------------                    
 Win32NT             10.0.18362.0 Microsoft Windows NT 10.0.18362.0
sdwheeler commented 4 years ago

I am still not able to reproduce your problem. The ellipsis character in the filename works on my machine.

PS C:\temp\test> dir

    Directory: C:\temp\test

Mode                 LastWriteTime         Length Name                                                                                                                 
----                 -------------         ------ ----                                                                                                                 
d-----          6/1/2020   2:01 PM                5.1                                                                                                                  
d-----          6/1/2020   1:57 PM                6                                                                                                                    
d-----          6/1/2020   1:56 PM                7.0                                                                                                                  
d-----          6/4/2020   1:28 PM                Щербакова Галина - …Все это следует шить                                                                             
-a----          6/1/2020   4:32 PM         282259 docs.txt                                                                                                             
-a----          6/1/2020   4:22 PM         241971 platy.txt                                                                                                            
-a----          6/4/2020   8:32 AM            561 test(2).txt                                                                                                          
-a----          6/4/2020   8:32 AM            496 test[1].txt                                                                                                          
-a----          6/4/2020   1:23 PM          30225 Щербакова Галина - …Все это следует шить.zip                                                                         

PS C:\temp\test> [int][char]'…'
8230

PS C:\temp\test> $PSVersionTable

Name                           Value                                                                                                                                   
----                           -----                                                                                                                                   
PSVersion                      5.1.19041.1                                                                                                                             
PSEdition                      Desktop                                                                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                 
BuildVersion                   10.0.19041.1                                                                                                                            
CLRVersion                     4.0.30319.42000                                                                                                                         
WSManStackVersion              3.0                                                                                                                                     
PSRemotingProtocolVersion      2.3                                                                                                                                     
SerializationVersion           1.1.0.1                         
skhodzhaev commented 4 years ago

Have you tried to use Expand-Archive on such file?

skhodzhaev commented 4 years ago

ExpandIt.zip The problem is with names of files inside a zip. Try to expand a zip with a file with ellipses in name. PS I've attached an example zip

sdwheeler commented 4 years ago

It works for me.

PS> Expand-Archive .\ExpandIt.zip
PS C:\temp\test> cd .\ExpandIt\
PS C:\temp\test\ExpandIt> dir

    Directory: C:\temp\test\ExpandIt

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          6/5/2020   1:01 AM              4 TryIt….txt
skhodzhaev commented 4 years ago

Well, further investigation gives this. Having two archives - Bad.zip is created by WinRAR and Good.zip is created by 7Zip. Expand-Archive works fine with Good.zip Expand-Archive can't get name of zipped file from Bad.zip properly and throws an error while WinRAR, 7zip or FileExplorer extract file from Bad.zip with its original name Looks like WinRAR encodes filename differently comparing to 7zip/Compress-Archive Bad.zip Good.zip

Sorry for my importunity

sdwheeler commented 4 years ago

Oh, interesting. That is good to know about WinRAR.