This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: zipfile module weird behavior when used with zipinfo
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Micheal Gardner, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-06-29 00:57 by Micheal Gardner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg320692 - (view) Author: Micheal Gardner (Micheal Gardner) Date: 2018-06-29 01:04
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
```
msg320704 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-06-29 06:29
Use:

rel_name = "tmp/test.md"
History
Date User Action Args
2022-04-11 14:59:02adminsetgithub: 78174
2018-06-29 06:29:18serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg320704

resolution: not a bug
stage: resolved
2018-06-29 01:04:17Micheal Gardnersetmessages: + msg320692
2018-06-29 00:57:40Micheal Gardnercreate