diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-04 13:42:28 +0300 |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-04 13:42:28 +0300 |
| commit | 90c24c42b2dc912c5b6b2e34d1d4a03a9a7de915 (patch) | |
| tree | 64c513bfca03777135f95139b7817aca0b5c1fc1 /Lib/zipfile.py | |
| parent | 84bf989cc29ca2062439c1aaea0c60d3088b320a (diff) | |
| parent | 518e71b18a008947b17369de5c06d9543db7dfc5 (diff) | |
| download | cpython-git-90c24c42b2dc912c5b6b2e34d1d4a03a9a7de915.tar.gz | |
Issue #22219: The zipfile module CLI now adds entries for directories
(including empty directories) in ZIP file.
Diffstat (limited to 'Lib/zipfile.py')
| -rw-r--r-- | Lib/zipfile.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 7e07f11d79..bda6134357 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1790,14 +1790,21 @@ def main(args = None): if os.path.isfile(path): zf.write(path, zippath, ZIP_DEFLATED) elif os.path.isdir(path): + if zippath: + zf.write(path, zippath) for nm in os.listdir(path): addToZip(zf, os.path.join(path, nm), os.path.join(zippath, nm)) # else: ignore with ZipFile(args[1], 'w') as zf: - for src in args[2:]: - addToZip(zf, src, os.path.basename(src)) + for path in args[2:]: + zippath = os.path.basename(path) + if not zippath: + zippath = os.path.basename(os.path.dirname(path)) + if zippath in ('', os.curdir, os.pardir): + zippath = '' + addToZip(zf, path, zippath) if __name__ == "__main__": main() |
