[issue33993] zipfile module weird behavior when used with zipinfo

Micheal Gardner report at bugs.python.org
Thu Jun 28 21:04:17 EDT 2018


New submission from Micheal Gardner <twocucao at gmail.com>:

when i want to zip a empty folder, i use following code

```

import zipfile

zfile = zipfile.ZipFile("tmp.zip",'w')
zif = zipfile.ZipInfo("tmp/")
zfile.writestr(zif,"")
zfile.close()
```

but in this case, things become weird.

```
# 先造一个测试文件夹
mkdir /tmp/test_folder/
touch /tmp/test_folder/test.md
```

```
import zipfile
file_path = "/tmp/test_folder/test.md"
rel_name = "test.md"
zfile = zipfile.ZipFile("tmp.zip",'w')
zif = zipfile.ZipInfo("tmp/")
zfile.writestr(zif,"")
zfile.write(file_path, rel_name)
zfile.close()
```

decompression expect 

```
$ tree tmp
tmp
├── test.md

1 file
```

decompression actual

```
$ tree tmp
tmp
├── test.md
└── tmp

1 directory, 1 file
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33993>
_______________________________________


More information about the Python-bugs-list mailing list