Skip to content

Compress-Archive creates zero files duplicating directories #27

@dermeister0

Description

@dermeister0

Steps to reproduce

Execute a test script.

if (Test-Path 'Root')
{
    Remove-Item 'Root' -Recurse -Force
}
Remove-Item *.zip

$path = 'Root\Level0\LastDir'
New-Item -ItemType Directory $path | Out-Null
New-Item -ItemType Directory "$path\EmptyDir" | Out-Null
Set-Content "$path\Document.txt" (Get-Date)

Compress-Archive 'Root' 'Test1.zip'

Add-Type -AssemblyName 'System.IO.Compression.FileSystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory("$PSScriptRoot\Root", "$PSScriptRoot\Test2.zip")

$sevenZip = 'C:\Program Files\7-Zip\7z.exe'
if (Test-Path $sevenZip)
{
    &$sevenZip a 'Test3.zip' 'Root'
}

Test1.zip is created by PowerShell, Test2.zip - by .NET 4.5 ZipFile, Test3.zip - by 7-Zip.

Test1.zip can't be extracted.

2017-02-02_2210_001

2017-02-02_2212

Test2.zip has invalid zero file instead of empty directory.

2017-02-02_2206

Test3.zip is correct.

2017-02-02_2210

Expected behavior

Created archive with correct structure.

Root/Level0/LastDir/EmptyDir/
Root/Level0/LastDir/Document.txt

Actual behavior

Every directory that does not contain files has a duplicating zero-length file in the archive.
Empty directory is converted to file.

Root/Level0/LastDir/Document.txt
Root/Level0/LastDir/EmptyDir
Root/Level0

2017-02-02_2152

2017-02-02_2153

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14393.693
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.693
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions