py7zr icon indicating copy to clipboard operation
py7zr copied to clipboard

Cannot add empty directory structures to output.

Open noisysoil opened this issue 3 years ago • 4 comments

Describe the bug When an archive structure in memory contains empty directories such as: empty-dir1/empty-dir2/empty-dir3 ...then when adding these to an archive, they do not appear in the final output.

To Reproduce Create a .7z file with an empty directory structure; taking the example above ('empty-dir1/empty-dir2/empty-dir3'): 7z a empty-dir-test.7z empty-dir1

Then recompress the test file with py7zr:

            compression_filters = [{'id': py7zr.FILTER_LZMA2, 'preset': 9}]
            with py7zr.SevenZipFile(f"test-output.7z", mode="w",
                                    filters=compression_filters) as target:
                with py7zr.SevenZipFile(f"empty-dir-test.7z", mode='r') as source:
                    target.writed(source.readall())

Expected behavior Directory structure should be preserved.

Environment (please complete the following information):

  • OS: Kubuntu Linux 21.10
  • Python 3.9
  • py7zr version: 0.17.3

Test data(please attach in the report): An archive structure containing an empty directory (see 'To reproduce').

noisysoil avatar Jan 27 '22 11:01 noisysoil

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jul 18 '22 00:07 github-actions[bot]

readall method returns Dict[filename: str, object: io.BytesIO] that cannot return a directory as entry. Are there any idea to express directory?

miurahr avatar Aug 03 '22 07:08 miurahr

Hi, There is a way to write empty directories and maintain their structure:

import py7zr
import tempfile
with py7zr.SevenZipFile(f"test-output.7z", mode="w") as target:
    target.write(tempfile.mkdtemp(), "empty-dir1/empty-dir2/empty-dir3")

It should be explained in the docs.

Ru13en avatar Sep 07 '22 14:09 Ru13en

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Dec 07 '22 00:12 github-actions[bot]