{"id":1810,"date":"2009-10-21T01:39:28","date_gmt":"2009-10-20T16:39:28","guid":{"rendered":"http:\/\/fukata.org\/?p=1810"},"modified":"2017-08-11T22:59:08","modified_gmt":"2017-08-11T22:59:08","slug":"python-recursive-zip-directory","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/1810\/","title":{"rendered":"[Python]\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u307e\u3068\u3081\u3066zip\u5727\u7e2e"},"content":{"rendered":"

python\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u898b\u3066\u3044\u308b\u3068\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092zip\u5727\u7e2e\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n

\r\n# -*- coding: utf-8 -*-\r\nimport os,zipfile\r\n\r\ndef zip_write_dir(base_dir, src_dir, zip_name):\r\n    \"\"\"\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092zip\u5727\u7e2e\u3059\u308b\r\n        base_dir: src_dir\u304c\u5c5e\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8868\u3059\r\n        src_dir: \u5727\u7e2e\u5bfe\u8c61\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8868\u3059\r\n        zip_name: \u51fa\u529b\u5148\u306ezip\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30eb\u30d1\u30b9\u3092\u8868\u3059\r\n    \"\"\"\r\n    zf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)\r\n\r\n    current_dir = os.getcwd();\r\n    os.chdir(base_dir)\r\n\r\n    for root,dirs,files in os.walk(src_dir):\r\n        for _file in files:\r\n            filename = os.path.join(root,_file)\r\n            arcname = filename\r\n            zf.write(filename, arcname)\r\n\r\n    zf.close()\r\n    os.chdir(current_dir)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

python\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u3092\u898b\u3066\u3044\u308b\u3068\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092zip\u5727\u7e2e\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002 # -*- coding: utf-8 -*- import os,zipfile … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[1086,104,399],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/1810"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=1810"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/1810\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=1810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=1810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=1810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}